Powershell:打开HTM和另存为XLS

是否有可能让Powershell打开.HTM并保存为.XLS。 我的HTM文件是一个表格,我希望格式化进行到哪个规则了一个CSV。 我已经尝试了使用保存的各种方法,但是它只是保存带有.XLS扩展名的文件,而仍然是一个.HTM文件。 我相信我只需要在下面的脚本的中间部分填入另存为代码。 任何援助将不胜感激。

$Excel = New-Object -comobject Excel.Application $FilePath = "C:\ScriptRepository\Results\Test.htm" $Workbook = $Excel.Workbooks.Open($FilePath) $Excel.Visible = $true $Excel.DisplayAlerts = $False $Excel.Workbooks.Close() $Excel.Quit() [System.GC]::Collect() [System.GC]::WaitForPendingFinalizers() [System.Runtime.Interopservices.Marshal]::ReleaseComObject($WorkBook) [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel) Remove-Variable -Name excel 

保存时,传递输出文件path和枚举51 ,告诉Excel使用xlsx文件types。

查看SaveAs文档页面和XlFileFormat枚举页面获取更多信息。

 $OutFile = "c:\mypath\to\my.xlsx" $xlSLSXType = 51 $workBook.SaveAs("$OutFile",$xlSLSXType)