Dear monks,
What I have is a program that prints reports using Win32::OLE and MS Excel. The user can select any number of reports that they want to run. The reports are created and printed using Excel. However I can't quite get the print options/behavior that I am looking for.
Once the user presses the <PRINT> button the following code is executed for each report.
my $rpt = GTIMs::Report->new('Schedule::Daily', $args);
$rpt->create; # populate the workbook with data
$rpt->print; # print the workbook
$rpt->destroy; # destroy the workbook
########################
# the report print function simply looks like this
sub print
{
my ($self, $copies) = @_;
$copies = 1 unless $copies;
$self->{WorkBook}->PrintOut(Copies => 1);
}
Now the issue is, as that printing like this, I can't select the printer to print to and advanced options like double sided printing, resolution, layout type, etc.
Things like paper type and orientation can be set using PageSetup (an example is provided below)
with ($Sheet->PageSetup,
LeftHeader => '',
CenterHeader => '&"Arial,Bold"&16' . $self->{Schedule}{$schedu
+le}{Title} . chr(10) .
"&12 $day $self->{Period}{Start}" . chr(10) .
"$start - $end",
RightHeader => '',
LeftFooter => 'Printed &D &T',
CenterFooter => '',
RightFooter => 'Page &P of &N',
LeftMargin => $Sheet->Application->InchesToPoints(0.15),
RightMargin => $Sheet->Application->InchesToPoints(0.15),
TopMargin => $Sheet->Application->InchesToPoints(1.0),
BottomMargin => $Sheet->Application->InchesToPoints(0.5),
HeaderMargin => $Sheet->Application->InchesToPoints(0.25),
FooterMargin => $Sheet->Application->InchesToPoints(0.25),
PrintHeadings => 0,
PrintGridlines => 0,
PrintComments => xlPrintNoComments,
PrintQuality => 600,
CenterHorizontally => 1,
CenterVertically => 0,
Orientation => xlPortrait,
Draft => 0,
PaperSize => xlPaperLetter,
FirstPageNumber => xlAutomatic,
Order => xlDownThenOver,
BlackAndWhite => 0,
Zoom => Variant(VT_BOOL, 0),
FitToPagesWide => 1,
FitToPagesTall => 1,
PrintErrors => xlPrintErrorsDisplayed,
PrintTitleRows => '$1:$2',
PrintTitleColumns => '$A:$D',
);
After some searching (I hope the below examples help others in a similar situation) I was able come up with the following code to display the print dialog.
use constant xlDialogPrint => 8;
sub print
{
my $self = shift;
my $dlg = $self->{Excel}->Dialogs(xlDialogPrint);
my $response = $dlg->Show;
}
This displays the print dialog, and you can change these settings. Exactly what I want to do. The problem is that it is going to display the print dialog for EVERY report the user wants to print. Which could be potentially be a pretty large number. I want to display the dialog once, and then use the same print settings for each document that I am printing. Does anyone have any insight into this?