#!/usr/bin/perl -w ####################################################################### # # Example of how write to alternative filehandles. # # March 2001, John McNamara, jmcnamara@cpan.org # use strict; use Spreadsheet::WriteExcel; use IO::Scalar; # # Example 1. Write an Excel file to a string. # # Refer to the IO::Scalar documentation my $xls_str; tie *XLS, 'IO::Scalar', \$xls_str; my $workbook1 = Spreadsheet::WriteExcel->new(\*XLS); my $worksheet1 = $workbook1->addworksheet(); $worksheet1->write(0, 0, "Hi Excel!"); $workbook1->close(); # This is required # The Excel file is now in $xls_str. # If you write it to a new file remember to binmode() the filehandle. # # Example 2. Write an Excel file to an existing filehandle. # open TEST, "> mytest1.xls"; my $workbook2 = Spreadsheet::WriteExcel->new(\*TEST); my $worksheet2 = $workbook2->addworksheet(); $worksheet2->write(0, 0, "Hi Excel!"); $workbook2->close(); # # Example 3. Write an Excel file to an OO style filehandle. # my $fh = FileHandle->new("> mytest2.xls"); my $workbook3 = Spreadsheet::WriteExcel->new($fh); my $worksheet3 = $workbook3->addworksheet(); $worksheet3->write(0, 0, "Hi Excel!"); $workbook3->close();