Powershell Script to convert txt to xlsx

主宰稳场 提交于 2019-12-24 08:56:20

问题


I want to convert a textfile to Excel Format. I use the following script from Technet:

# Script name: ConvertTilde.ps1 
# Created on: 2007-01-06 
# Author: Kent Finkle 
# Purpose: How Can I Convert a Tilde-Delimited File to Microsoft Excel Format? 

$s = gc C:\Scripts\Test.txt 
$s = $s -replace("~","`t") 
$s | sc C:\Scripts\Test.txt 
$xl = new-object -comobject excel.application 
$xl.Visible = $true 
$wb = $xl.Workbooks.Open("C:\Scripts\Test.txt")
$wb.SaveAs(“D:\Excel\Test.xlsx”)

The Script works, excel opens and imports the txt, but the saved Files are just txt files renamed to xlsx - how can I get Excel to change the File Format?


回答1:


I would investigate the FileFormat parameter of the SaveAs method, although it won't magically convert a text file into a nicely formatted workbook.



来源:https://stackoverflow.com/questions/22560483/powershell-script-to-convert-txt-to-xlsx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!