I have an Excel document that contains multiple sheets. I use the powershell to export the document to PDF, but unfortunately FitToPagesTall and FitToPagesWide do not work for me. I need the columns in the pdf document to be adapted to the page. Alternatively, please advise how to set the format (A4, A3). Can someone please advise me. Thank you
$path = "C:\doc\" $xlFixedFormat = "Microsoft.Office.Interop.Excel.xlFixedFormatType" -as [type] $excelFiles = Get-ChildItem -Path $path -include *.xls, *.xlsx -recurse $objExcel = New-Object -ComObject excel.application $objExcel.visible = $false foreach($wb in $excelFiles) { $filepath = Join-Path -Path $path -ChildPath ($wb.BaseName + ".pdf") $workbook = $objExcel.workbooks.open($wb.fullname, 3) $workbook .PageSetup.Zoom = $false $workbook .PageSetup.FitToPagesTall = 2 $workbook .PageSetup.FitToPagesWide = 2 $workbook.Saved = $true "saving $filepath"$workbook.ExportAsFixedFormat($xlFixedFormat::xlTypePDF, $filepath)
$objExcel.Workbooks.close()
}
$objExcel.Quit()