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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
$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) <strong>$workbook .PageSetup.Zoom = $false $workbook .PageSetup.FitToPagesTall = 2 $workbook .PageSetup.FitToPagesWide = 2</strong> $workbook.Saved = $true "saving $filepath" $workbook.ExportAsFixedFormat($xlFixedFormat::xlTypePDF, $filepath) $objExcel.Workbooks.close() } $objExcel.Quit() |