Skip to content

Instantly share code, notes, and snippets.

@tobynet
Created April 20, 2014 22:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobynet/11127306 to your computer and use it in GitHub Desktop.
Save tobynet/11127306 to your computer and use it in GitHub Desktop.
function saveAsPdf($filename) {
echo ("Converting {0}" -f $filename)
$excel = New-Object -ComObject Excel.Application -Property @{visible=$false}
try {
$excel.AlertBeforeOverwriting = $true
$workbook = $excel.Workbooks.Open($filename)
$workbook.ExportAsFixedFormat(
[Microsoft.Office.Interop.Excel.XlFixedFormatType]::xlTypePDF ,
[Io.Path]::ChangeExtension($filename, '.pdf') ,
[Microsoft.Office.Interop.Excel.XlFixedFormatQuality]::xlQualityStandard
)
} finally {
$excel.Quit()
}
}
echo $("Begin to convert {0} files to PDF" -f $args.Length)
$args | %{ saveAsPdf -filename $_ }
echo "DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment