Hi all ...
I have searched through the archives for an answer and have found a lot of
discussion, but nothing concrete enough to help ...
I am using Spreadsheet::WriteExcel to create an Excel doc (hence the name)
but I keep getting blank documents back.
The module can write to a file or to STDOUT using '-'. From the archives I
see that this is similar to an issue with Apache::Magick where the C STDOUT
(expressed as '-' or '>-') is different from Perl's default STDOUT.
I have also tried the code from the mod_perl guide:
use constant IS_MODPERL => $ENV{MOD_PERL};
if (IS_MODPERL) {
tie *OUT, 'Apache';
} else {
open (OUT, ">-");
}
I'm probably not using this as intended, though (an example would help).
Does this go before the handler sub, or in it ???
Here is the code below (BTW it does work as a plain cgi script w/o the
mod_perl additions of course). You can see the different ways I have been
trying to do this ...
package Planning_xls;
# File: /usr/local/apache/lib/perl/Planning_xls.pm
use strict;
use Apache::Constants qw(:common REDIRECT HTTP_SERVICE_UNAVAILABLE);
use Spreadsheet::WriteExcel;
sub handler {
my $r = shift;
use constant IS_MODPERL => $ENV{MOD_PERL};
if (IS_MODPERL) {
tie *OUT, 'Apache';
} else {
open (OUT, ">-");
}
# *STDOUT = *r{IO};
# tie *STDOUT => Apache;
# tie *STDOUT => $r;
# tie *STDOUT => 'Apache';
# open(STDOUT, ">-");
# untie *STDOUT;
# open(STDOUT, ">&=" . fileno($fh));
$r->content_type('application/vnd.ms-excel');
# $r->content_type('text/html');
$r->send_http_header;
my $workbook = Spreadsheet::WriteExcel->new("-");
# my $workbook = Spreadsheet::WriteExcel->new(STDOUT);
my $worksheet = $workbook->addworksheet("test");
my $format = $workbook->addformat();
$format->set_bold();
$format->set_color('red');
$format->set_align('center');
$worksheet->write(0, 0, 1);
$worksheet->write(1, 1, 1.2345);
$worksheet->write(2, 2, "formatted", $format);
$workbook->close();
return OK;
}
1;
__END__
Thanks for any help ... I know I am missing something obvious ...
Dave Homsher
Webmaster
MACtac IT
"The tree of liberty must be watered
periodically with the blood of tyrants and patriots alike.
... Resistance to tyrants is obedience to God."
- Thomas Jefferson