NAME
Spreadsheet::SimpleExcel - Perl extension for creating excel-files quickly
SYNOPSIS
use Spreadsheet::SimpleExcel;
binmode(\*STDOUT);
# data for spreadsheet
my @header = qw(Header1 Header2);
my @data = (['Row1Col1', 'Row1Col2'],
['Row2Col1', 'Row2Col2']);
# create a new instance
my $excel = Spreadsheet::SimpleExcel->new();
# add worksheets
$excel->add_worksheet('Name of Worksheet',{-headers => \@header, -data => \@data});
$excel->add_worksheet('Second Worksheet',{-data => \@data});
$excel->add_worksheet('Test');
# add a row into the middle
$excel->add_row_at('Name of Worksheet',1,[qw/new row/]);
# sort data of worksheet - ASC or DESC
$excel->sort_data('Name of Worksheet',0,'DESC');
# remove a worksheet
$excel->del_worksheet('Test');
# create the spreadsheet
$excel->output();
# get the result as a string
my $spreadsheet = $excel->output_as_string();
# print result into a file
$excel->output_to_file("my_excel.xls");
## or
# data
my @data2 = (['Row1Col1', 'Row1Col2'],
['Row2Col1', 'Row2Col2']);
my $worksheet = ['NAME',{-data => \@data2}];
# create a new instance
my $excel2 = Spreadsheet::SimpleExcel->new(-worksheets => [$worksheet]);
# add headers to 'NAME'
$excel2->set_headers('NAME',[qw/this is a test/]);
# append data to 'NAME'
$excel2->add_row('NAME',[qw/new row/]);
$excel2->output();
DESCRIPTION
Spreadsheet::SimpleExcel simplifies the creation of excel-files in the web. It does not provide any access to cell-formats yet. This is just a raw version that will be extended within the next few weeks.
METHODS
new
# create a new instance
my $excel = Spreadsheet::SimpleExcel->new();
# or
my $worksheet = ['NAME',{-data => ['This','is','an','Test']}];
my $excel2 = Spreadsheet::SimpleExcel->new(-worksheets => [$worksheet]);
# to create a file
my $filename = 'test.xls';
my $excel = Spreadsheet::SimpleExcel->new(-filename => $filename);
add_worksheet
# add worksheets
$excel->add_worksheet('Name of Worksheet',{-headers => \@header, -data => \@data});
$excel->add_worksheet('Second Worksheet',{-data => \@data});
$excel->add_worksheet('Test');
The first parameter of this method is the name of the worksheet and the second one is a hash with (optional) information about the headlines and the data.
del_worksheet
# remove a worksheet
$excel->del_worksheet('Test');
Deletes all worksheets named like the first parameter
add_row
# append data to 'NAME'
$excel->add_row('NAME',[qw/new row/]);
Adds a new row to the worksheet named 'NAME'
add_row_at
# add a row into the middle
$excel->add_row_at('Name of Worksheet',1,[qw/new row/]);
This method inserts a row into the existing data
sort_data
# sort data of worksheet - ASC or DESC
$excel->sort_data('Name of Worksheet',0,'DESC');
sort_data sorts the rows
set_headers
# add headers to 'NAME'
$excel->set_headers('NAME',[qw/this is a test/]);
set the headers for the worksheet named 'NAME'
output
$excel2->output();
prints the worksheet to the STDOUT and prints the Mime-type 'application/vnd.ms-excel'.
output_as_string
# get the result as a string
my $spreadsheet = $excel->output_as_string();
returns a string that contains the data in excel-format
output_to_file
# print result into a file
$excel->output_to_file("my_excel.xls");
prints the data into a file. There is a limitation in allowed characters for the filename: A-Za-z0-9/._ Other characters will be deleted.
DEPENDENCIES
This module requires Spreadsheet::WriteExcel and IO::Scalar
BUGS
I'm sure there are some bugs in this module. Feel free to contact me if you experienced any problem.
SEE ALSO
Spreadsheet::WriteExcel IO::Scalar
AUTHOR
Renee Baecker, <module@renee-baecker.de>
COPYRIGHT AND LICENSE
Copyright (C) 2004 by Renee Baecker
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.1 or, at your option, any later version of Perl 5 you may have available.