deadfish
deadfish

Reputation: 12304

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

Upvotes: 2

Views: 5547

Answers (1)

Shay Levy
Shay Levy

Reputation: 126722

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()

Upvotes: 5

Related Questions