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:\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”) 

脚本工程,excel打开并导入txt,但保存的文件只是txt文件重命名为xlsx – 我怎样才能让Excel更改文件格式?

我将调查SaveAs方法的FileFormat参数,虽然它不会神奇地将文本文件转换为格式良好的工作簿。