Convert excel to pdf


25804i9DC9C85FFF5EB391.jpg25805i5DE9DE1B24C92D45.jpg25806iB1915690B2636121.jpg 

$_dollar$filepath = '$pathconvertfile$'

 

$_dollar$fileitem = Get-Item $_dollar$filepath

 

try {

  $_dollar$excel = New-Object -ComObject Excel.Application

  $_dollar$excel.Visible = $_dollar$false

  $_dollar$excel.DisplayAlerts = $_dollar$false

 

  $_dollar$wb = $_dollar$excel.Workbooks.Open($_dollar$fileitem.FullName)

 

  $_dollar$pdfpath = $_dollar$fileitem.DirectoryName + """ + $_dollar$fileitem.BaseName + ".pdf"

 

  $_dollar$wb.ExportAsFixedFormat([Microsoft.Office.Interop.Excel.XlFixedFormatType]::xlTypePDF, $_dollar$pdfpath)

 

  $_dollar$wb.Close()

 

  $_dollar$excel.Quit()

}

finally {

  $_dollar$sheet, $_dollar$wb, $_dollar$excel | ForEach-Object {

    if ($_dollar$_ -ne $_dollar$null) {

      [void][System.Runtime.Interopservices.Marshal]::ReleaseComObject($_dollar$_)

    }

  }

}


0 replies

Be the first to reply!

Reply