Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: save excel as pdf (OLE)

by jf200399 (Initiate)
on Nov 06, 2012 at 17:03 UTC ( #1002526=note: print w/ replies, xml ) Need Help??


in reply to Re^3: save excel as pdf (OLE)
in thread save excel as pdf (OLE)

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);


Comment on Re^4: save excel as pdf (OLE)
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002526]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-11-27 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (184 votes), past polls