PowerShell把Excel表格转换成PDF文档


############################################################
# 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
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

关于 Mooser Lee

我是一个Powershell的爱好者,创建了PowerShell中文博客,热衷于Powershell技术的搜集和分享。本站部分内容来源于互联网,不足之处敬请谅解,并欢迎您批评指正。

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注