Soldato
I'm mucking about with a little code which basically recurses through a folder and exports a worksheet from a workbook to PDF. The issue I'm having to trying to include reference to either page setup/orientation or print area so the PDF created is either set to landscape or fit to page mode.
Would appreciate any pointers!
Thanks, Paul.
Code:
$path = ""
$xlFixedFormat = "Microsoft.Office.Interop.Excel.xlFixedFormatType" -as [type]
$filter = Get-ChildItem -Path $path -include *.xlsx -recurse
$objExcel = New-Object -ComObject excel.application
$objExcel.visible = $false
foreach($wb in $filter)
{
#$filepath = ($wb.FullName -replace '.xlsx?$', '.xps') #xps
$filepath = ($wb.FullName -replace '.xlsx?$', '.pdf')
$workbook = $objExcel.workbooks.open($wb.fullname, 3)
$workbook.Saved = $true
$Worksheets = $Workbook.worksheets
$Worksheet = $Workbook.worksheets.Item(1)
#$Workbook.PageSetup.Orientation = landscape #Like this worked! :)
#$Worksheet.ExportAsFixedFormat($xlFixedFormat::xlTypeXPS, $filepath) #xps
$Worksheet.ExportAsFixedFormat($xlFixedFormat::xlTypePDF, $filepath)
$objExcel.Workbooks.close()
}
$objExcel.Quit()
Thanks, Paul.