Minor changes
use strict; use warnings; use File::Spec::Functions qw(rel2abs); use Win32::OLE qw(in with); use Win32::OLE::Variant; use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; # die on errors... print "$0 - Wandle Excel-Datei in PDF um ...\n\n"; # Dateiname der Excel-Datei holen und kompletten Pfad ergänzen my $filename = shift; $filename = rel2abs($filename); print "Ausgangsdatei $filename\n"; # PDF-Dateinamen festlegen my $pdffilename = $filename; $pdffilename =~ s/\.xls.*/\.pdf/i; # Wenn PDF-Datei schon existiert, dann löschen if ( -e $pdffilename ) { print "PDF-Datei $pdffilename existiert schon ... wird geloescht.\ +n"; unlink($pdffilename); } else { print "PDF-Datei $pdffilename\n"; } # Open document # Create new MSExcel object and load constants my $MSExcel = Win32::OLE->new( 'Excel.Application', 'Quit' ) or die "Could not load MS Excel"; my $excel = Win32::OLE::Const->Load($MSExcel); my $Book = $MSExcel->Workbooks->Open( { FileName => "$filename" } ); # Excel-Funktion "Speichern unter ..." aufrufen $Book->ExportAsFixedFormat( { 'Type' => xlTypePDF, 'Filename' => "$pdffilename", 'Quality' => xlQualityStandard, 'IncludeDocProperties' => "True", 'IgnorePrintAreas' => "False", 'OpenAfterPublish' => "False", } ); # Close document $Book->Close( { SaveChanges => $excel->{xlDoNotSaveChanges} } ); if ( -e $pdffilename ) { print "PDF-Datei wurde erzeugt. Programmende.\n"; } else { print "Fehler: Datei $pdffilename wurde nicht erzeugt. Programmend +e.\n"; } exit(0);

In reply to Re^4: save excel as pdf (OLE) by jf200399
in thread save excel as pdf (OLE) by Anonymous Monk

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.