Reputation: 41
is it possible to have Powershell open a .HTM and save as an .XLS. My HTM file is a table that I would like the formatting carried though to which rules out a CSV. I have tried various methods using save as however it just saves the file with the .XLS extension whilst still being an .HTM file. I believe I just need the middle part of the script below filled in with the Save As code. Any assistance would be greatly appreciated.
$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
Upvotes: 0
Views: 2072
Reputation: 10019
When saving, pass the output file path and the enum 51
, which tells Excel to use the xlsx
filetype.
Check out the SaveAs documentation page, and XlFileFormat enumerations page for more info.
$OutFile = "c:\mypath\to\my.xlsx"
$xlSLSXType = 51
$workBook.SaveAs("$OutFile",$xlSLSXType)
Upvotes: 2