Powershell脚本转换txt到xlsx



我想将一个文本文件转换为Excel格式。我使用以下来自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:ScriptsTest.txt 
$s = $s -replace("~","`t") 
$s | sc C:ScriptsTest.txt 
$xl = new-object -comobject excel.application 
$xl.Visible = $true 
$wb = $xl.Workbooks.Open("C:ScriptsTest.txt")
$wb.SaveAs(“D:ExcelTest.xlsx”)

脚本工作,excel打开并导入txt,但保存的文件只是重命名为xlsx的txt文件-我怎么能让excel改变文件格式?

我将研究savea方法的FileFormat参数,尽管它不会神奇地将文本文件转换为格式良好的工作簿。

最新更新