Excel 用于将txt转换为xlsx的Powershell脚本

Excel 用于将txt转换为xlsx的Powershell脚本,excel,powershell,text-files,Excel,Powershell,Text Files,我想将文本文件转换为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("~",

我想将文本文件转换为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,但保存的文件只是重命名为xlsx的txt文件-如何让excel更改文件格式?

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

这很容易,感谢您的帮助:
$xlFixedFormat=Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbook$wb.SaveAs(“D:\Excel\Test.xlsx”,$xlFixedFormat)