Created
April 20, 2014 22:54
-
-
Save tobynet/11127306 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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