Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Spreadsheet-SimpleExcel CPAN distribution.

Report information
The Basics
Id: 8218
Status: resolved
Priority: 0/
Queue: Spreadsheet-SimpleExcel

People
Owner: Nobody in particular
Requestors: drew [...] drewtaylor.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: [PATCH] Add support for getting excel data w/o printing to STDOUT
Download (untitled) / with headers
text/plain 1.9k
I'd like to be able to get the Excel data in a scalar instead of always printing to STDOUT. Here's a patch that adds a output_as_string() method which accomplishes it. It does add the requirement of IO::Scalar, but I believe that is included in later perl distributions. I don't have a more recent perl than 5.005 handy so this patch is mostly untested. :-) That said, I believe it should work. diff -u Spreadsheet-SimpleExcel.pm.orig Spreadsheet-SimpleExcel.pm --- Spreadsheet-SimpleExcel.pm.orig Tue Nov 2 13:56:51 2004 +++ Spreadsheet-SimpleExcel.pm Tue Nov 2 14:09:49 2004 @@ -4,6 +4,7 @@ use strict; use warnings; use Spreadsheet::WriteExcel; +use IO::Scalar; require Exporter; @@ -101,11 +102,25 @@ return 1; }# end _is_numeric -sub output{ +sub output_as_string{ + my ($self) = @_; + $self->_make_excel; +} + +sub output { + my ($self) = @_; + print "Content-type: ".$self->{type}."\n\n"; + my $xls = $self->_make_excel; + print $$xls; +} + +sub _make_excel{ my ($self) = @_; - print "Content-type: ".$self->{type}."\n\n"; - my $EXCEL = new Spreadsheet::WriteExcel(\*STDOUT); + my $output; + tie(*XLS, 'IO::Scalar', \$output); + my $EXCEL = Spreadsheet::WriteExcel->new(\*XLS) + or die("Error creating spreadsheet object"); foreach my $worksheet(@{$self->{worksheets}}){ my $sheet = $EXCEL->addworksheet($worksheet->[0]); @@ -126,6 +141,8 @@ } } $EXCEL->close(); + + return $output; }# end output @@ -185,6 +202,8 @@ $excel2->add_row('NAME',[qw/new row/]); $excel2->output(); + # OR + my $xls = $excel2->output_as_string(); =head1 DESCRIPTION @@ -259,9 +278,15 @@ prints the worksheet to the STDOUT. +=head2 output_as_string + + my $xls = $excel2->output_as_string(); + +returns the excel data as a scalar reference + =head1 DEPENDENCIES -This module requires Spreadsheet::WriteExcel +This module requires Spreadsheet::WriteExcel and IO::Scalar =head1 BUGS


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.