print("Starting to convert...\n"); my $classname = "Excel.Application"; my $excel_obj = Win32::OLE->GetActiveObject( $classname ); if (!($excel_obj)) { print("no active object, creating new one...\n"); $excel_obj = new Win32::OLE($classname, \&QuitApp ) || die "Could not cretate an OLE '$classname' object"; print("Created.\n"); } else { print("Already existed.\n"); } if (!($excel_obj)) { print("Error during get/create of Excel object. returning 0."); return 0; } print("Proceeding...\n"); $excel_obj->{Visible} = 0; # EnableEvents=0 (on by default) disables (hopefully) # dialog boxes that # are waiting on user input, which is good for this program running # unattended as it hopefully will. $excel_obj->{EnableEvents} = 0; # note that open() takes params like: # open(filename, UpdateLinks, ReadOnly...) # See the O'reilly Excel with VBA book on this. my $Book = $excel_obj->Workbooks->Open( $infilename, 0, 1 ); # above line opens the file print("Opened file $infilename...\n"); if (!($Book)) { print("Error during open, filen=$infilename. returning 0."); return 0; } my $count = $Book->Worksheets()->{Count} || 0; print("$count worksheets are in Excel spreadsheet $infilename.\n\n"); my $pobj = $excel_obj->ActivePrinter; if ($pobj) { print("Name of default printer =>>$pobj<<\n"); } my @thing = $Book->PrintOut( { PrintToFile => 1, PrToFileName => $outfilename, ActivePrinter => "PS_FILE_OUTPUT on Ne00:", Copies => 1 }); ########################################### # note: following works on my Office 2000 and # Office XP, but not Excel 97. # PrintToFile => 1, # PrToFileName => $outfilename, ############################################## # Note: if you want a black and white PDF, # print to a black and white printer. ############################################# # printer options: # black and white: ActivePrinter => '\\NETPRINTSRV\p21 on Ne01:', # color: ActivePrinter => "PS_FILE_OUTPUT on Ne00:", # default printer: ActivePrinter => $pobj, # Kevin Rice's home: ActivePrinter => "PrinterPS5m on LPT2:", ########################################### $Book->Close(0); #$Book->{Parent}->Quit();