Search code examples
excelpowershellsave-as

How save excel 2007 in html format using powershell?


Hello i tried with that code

$e = New-Object -ComObject "Excel.Application"
$e.Visible = $true
$ew = $e.Workbooks.Open("C:\Users\mich\14_50_33__5_Pt_50_sie_2011.xls")
$ew.SaveAs("C:\Users\mich\Documents\test", "Excel.XlFileFormat.xlHtml")

What do i do wrong?


Here is my own working code:

$xlExcelHTML = 44
$Excel = New-Object -ComObject "Excel.Application"
$Excel.Visible = $true
$WorkBook = $Excel.Workbooks.Open("C:\Users\mich\14_50_33__5_Pt_50_sie_2011")
$WorkSheet = $WorkBook.Worksheets.Item(1)
$WorkBook.SaveAs("C:\temp\test8",$xlExcelHTML)

Here is a link for format extensions code: http://msdn.microsoft.com/en-us/library/bb241279(office.12).aspx


Solution

  • This is working for me. There are 12 arguments you need to pass to the saveAs method. Fill each unspecified arguments with [type]::Missing

    $xlHtml = 44
    $missing = [type]::Missing
    $xl = New-Object -ComObject Excel.Application
    $xl.Visible = $true
    $wb = $xl.Workbooks.Open('d:\book1.xlsx')
    $xl.ActiveWorkbook.SaveAs('d:book1.html',$xlHtml,$missing,$missing,$missing,$missing,$missing,$missing,$missing,$missing,$missing,$missing)
    $xl.Quit()