Follow sqlserver-dba.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

SQLServer-DBA.com Links

Dba_db2_button

dba-ninja.com

SQL Server DBA Jobs

SQL Server – Powershell Excel to HTML

19 January,2012 by Tom Collins

SQL Server, Powershell and Excel are a good mix . But saving to Powershell output to HTML is versatile – if requiring email attachments or publishing results to a web page .

 Any Powershell scripts using Excel as an end point can be converted to HTML with just a few lines of code.  Therefore you can keep the Powershell \  Excel code , and add some lines for HTML output.

 The convert process , creates well formatted HTML pages , ideal for reports.  Creating the reports in HTML makes them easier to read on my smartphone – which does a better job at web browsing rather than reading Excel

 

$xlHtml = 44
$omit = [type]::Missing
$Excel = New-Object -ComObject Excel.Application

--some activity e.g recordsets 
--would normally save Excel as :
--$EXcel.ActiveWorkbook.SaveAs("c:myfile.xls")
--instead save the workbook as html

$EXcel.ActiveWorkbook.SaveAs("c:myfile.html",$xlHtml,$omit,$omit,$omit,$omit,$omit,$omit,$omit,$omit,$omit,$omit)
$Excel.Quit()

 

See Also

Powershell , Excel charts and data presentation

Powershell to HTML

Powershell sql server security audit


Author: Tom Collins (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on SQL Server – Powershell Excel to HTML


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer