############################################################
# Convert Excel document to PDF
############################################################
function Convert-ExcelToPdf
{
param(
[io.fileinfo]$DocPath,
[string]$PdfPath
)
$xlFixedFormat = “Microsoft.Office.Interop.Excel.xlFixedFormatType” -as [type]
$objExcel = New-Object -ComObject excel.application
$workbook = $objExcel.workbooks.open($DocPath.fullname, 3)
$workbook.ActiveSheet.PageSetup.Orientation = 2
$objExcel.PrintCommunication = $false
$workbook.ActiveSheet.PageSetup.FitToPagesTall = $false
$workbook.ActiveSheet.PageSetup.FitToPagesWide = 1
$objExcel.PrintCommunication = $true
$workbook.Saved = $true
$workbook.ExportAsFixedFormat($xlFixedFormat::xlTypePDF, $PdfPath)
$objExcel.Workbooks.close()
$objExcel.Quit()
}
本文链接: https://www.pstips.net/convert-exceltopdf.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
