Using the code from Alain M. Samoun's article as a base [ w. Office 2000+php 4.2.3 CGI+Apache 2.0.42 on Win2000], I can get Word documents to print, but not Excel docs.
The error msg is 'unable to lookup PrintOut', and it hints to a bad function call (e.g. method called with wrong number/type of arguments, or on wrong object type), but I've taken the method definition and an axemple call straight out of an Excel Macro, so I'd expect it is correct...
Besides, I can't seem to set the printer either...
here's the code:
$ok = False;
echo "Starting Excel\n";
$xcel = new COM("Excel.Application");
if ($xcel){
// set display of alerts to false
$xcel->DisplayAlerts = False;
print "App name: {$xcel->value}<br />\n";
print "Loaded version: {$xcel->version}<br />\n";
echo "Opening Excel file\n";
$xcel->Workbooks->Open($file, 0, true); // not update links, read-only
if ($wkb){
/
echo "Setting printer: [$printer]\n";
if ($printer)
$xcel->ActivePrinter = $printer;
/
$sheet = $wkb->ActiveSheet;
echo 'Active sheet: ['.$sheet .']<br/>';
echo 'Active printer: ['.$xcel->ActivePrinter.']<br/>';
$ok = com_invoke($wkb, 'Printout',
1, // From:
100, // To:
1, // Copies:
False, // Preview:
$printer, // ActivePrinter:
True, // PrintToFile
False, // Collate
$outfile);
if ($ok === null)
$ok = False;
else
$ok = True;
echo "Closing document\n";
$wkb->Close(False);
}
echo "Closing Excel\n";
$xcel->Quit();
}
return $ok;
}