I am trying to save each worksheet(tab) in an Excel worksheet as a PDF or PNG. Here is what I have so far (doesn't work though). Can anyone help?

Note: I found the Excel constants at http://www.convert-files.com/SII/Convert-XLS/English/WebHelp/command_line_manual/file_type_constants/rhid_excel_conversion_file_type_constants.htm so I tried -1 as the FileFormat but it did not work.

Update: If this is not possible, is there a way to save the entire xlx file as PDF?

#!c:\perl\bin use strict; use Win32::OLE; use Win32::OLE qw(in with); use Win32::OLE::Variant; use Win32::OLE::Const 'Microsoft Excel'; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application'); $Excel->{'Visible'} = 1; #0 is hidden, 1 is visible $Excel->{DisplayAlerts}=1; #0 is hide alerts # Open File and Worksheet my $Book = $Excel->Workbooks->Open('C:\temp\XLS\test.xls'); my $cnt=0; foreach my $Worksheet (in $Book->{Worksheets}){ $cnt++; my $filename="C:\temp\XLS\test2\_$cnt.pdf"; print "saving $filename\n"; #HOW DO I SAVE THIS worksheet as a PDF or a PNG??? $Worksheet->SaveAs({Filename =>$filename,FileFormat => -1}); } # Save as Excel $Book->Close(); $Excel->Quit(); exit;
s/te/ve/

In reply to Save Excel worksheets as PDF by slloyd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.