Subject: | new( \*STDOUT ) Broken |
I have used new( \*STDOUT ) to stream dynamically created Excel files, but when I upgraded to 0.42 the output is now munged and not recognized by Excel. Doing a command line test:
Presuming "new( \*STDOUT )":
$ mk_excel.pl > testfile.xls
Produces output not recognized by Excel. If I change the command to "new( 'testfile.xls')":
$ mk_excel.pl
The testfile.xls file is perfectly fine, and looking at a byte by byte comparison is *substantially different* from the file created above. I presume from this that streaming to STDOUT is broken, or that the behavior has changed but the documentation has not been updated to reflect this.
I haven't tested to see if this is the case for any script, but here's a snippet that includes all the related calls:
# Create a new Excel workbook, output to STDOUT
$wkb = Spreadsheet::WriteExcel->new( \*STDOUT );
# Add a worksheet
$wks = $wkb->addworksheet();
# set column widths
@width = (22.50, 9.50, 9.50, 17.33, 8.50, 10, 5.17, 5.50, 7.83, 6, 9.50, 8.50, 7.17, 17.50, 7.17, 14.50, 12, 14.50, 22.50, 11.17, 24.50, 11.17);
for ( my $i = 0; $i<@width; $i++ ) {
$wks->set_column( $i, $i, $width[$i] );
}
# define formats
$format{default} = $wkb->addformat( font => 'Times New Roman', size => 12, align => 'left' );
$format{header} = $wkb->addformat( font => 'Times New Roman', size => 12, align => 'left', bold => 1 );
# Set header row
@cell = qw(EmailAddress FirstName LastName Address1 Address2 City State Zip Country Phone AgeRange DOB Gender Income Section Status Product SourceCode SourceDescription PromoCode PromoDescription Opt-inDate);
$wks->write( 'A1', \@cell, $format{header} );
# read from database
$count = 1;
while( @{$row_ref = $query->fetch_array} ) {
$count++;
@cell = ( @{$row_ref}, '', '', '', 'MH', 'COM001', 'USATODAY.com', 'MIL001', 'MileageManager registration', '' );
$wks->write( "A$count", \@cell, $format{default} );
}
$wkb->close;
---END---
Environment:
perl, v5.8.0 built for i386-linux-thread-multi
Linux 2.4.20-6 #1 Thu Feb 27 10:06:59 EST 2003 i686 i686 i386 GNU/Linux
(RedHat 9)