merrymonk has asked for the wisdom of the Perl Monks concerning the following question:

I am using the following Perl to save an Excel file as a PDF (found on the PerlMonks site).
This works well but I want to save it so that it just fits one page.
$Book->ExportAsFixedFormat( { Type => xlTypePDF, Filename => "$pdffilename", Quality => $excel->{xlQualityStandard}, IncludeDocProperties => $excel->{True}, IgnorePrintAreas => $excel->{False}, OpenAfterPublish => $excel->{False}, } );
I found the following on another web site
' The next 2 lines will force the PDF to fit the range onto one page ActiveSheet.PageSetup.FitToPagesWide = 1 ActiveSheet.PageSetup.FitToPagesTall = 1
I tried to adapt this for Perl with the following as I thought, if successful, it will be used in the IncludeDocProperties => $excel->{True}, option
$sheet = $Book -> Worksheets("Sheet1"); $sheet -> Activate; $sheet->PageSetup->FitToPagesWide = 1; $sheet->PageSetup->FitToPagesTall = 1;
However, I got the following error
Tk::Error: Can't modify non-lvalue subroutine call at the FitToPagesWide line
I would appreciate help to know:
1. If this is the correct method and if so what corrections to make;
2. If this is not the correct method how do I achieve getting just one page in the PDF file

Replies are listed 'Best First'.
Re: Excel saving as PDF as 1 page
by soonix (Chancellor) on Oct 24, 2015 at 21:01 UTC
    Can't test this now, but ISTR it should be
    $sheet->PageSetup->{FitToPagesWide} = 1; $sheet->PageSetup->{FitToPagesTall} = 1;
    Otherwise it's interpreted as method call instead of attribute access.
      Thank you. This did not give any failure messages.
      Sadly it did not work as the PDF file was written to two pages. Have you any idea how to make it use just one page?
        try
        use Win32::OLE qw(with); use Win32::OLE::Variant; my $vtfalse = Variant(VT_BOOL, 0); my $vtpages = Variant(VT_I4, 1); with ($sheet->PageSetup, 'Zoom' => $vtfalse, 'FitToPagesWide' => $vtpages, 'FitToPagesTall' => $vtpages );
        poj