|
OpenOffice::Parse::SXC - Perl extension for parsing OpenOffice SXC files |
OpenOffice::Parse::SXC - Perl extension for parsing OpenOffice SXC files
use OpenOffice::Parse::SXC qw( parse_sxc );
# Non-OO way:
my @rows = parse_sxc( "file.sxc" );
for( @rows ) {
print join(",", $_ ),"\n";
}
# OO way:
package MyDataHandler; # Set up a handler object
sub new {
my $type = shift;
my $self = {};
bless $self, $type;
return $self;
}
sub row {
my $self = shift;
my $SXC = shift;
my $row_data = shift;
print $self->{worksheet},": ",join(",", $_),"\n"; # Simple csv values printed...
}
sub worksheet {
my $self = shift;
my $SXC = shift;
my $worksheet = shift;
$self->{worksheet} = $worksheet;
}
sub workbook {
my $self = shift;
my $SXC = shift;
my $workbook = shift || "unknown_workbook";
}
1;
package Main;
my $SXC = OpenOffice::Parse::SXC->new( OPTIONS ); $SXC->set_data_handler( MyDataHandler->new ); $SXC->parse_file( "file.sxc" );
OpenOffice::Parse::SXC parses an SXC file (OpenOffice spreadsheet) and passes data back through a callback object that you register with the SXC object.
The major benefit of being able to read directly from an OpenOffice spreadsheet is that it allows SXC files to be directly used as a development tool.
The data returned contains no formatting or formula information, only what text is displayed in the spreadsheet.
This module requires XML::Parser and the compression utility unzip to be installed.
The data that this module will provide you with is exactly the same as what you would see in the OpenOffice application. This could be different than what you entered. For example, this module would provide the results of a function, not the function itself. If you enter 19.95 into a cell, and format that cell as a currency type, you would see $19.95 (for example), and that is what you would get using this module to parse the spreadsheet.
None by default.
The following options can be used (in new() or set_options()):
The DATA HANDLER is what the SXC object calls upon do do work while it parses an SXC file. It expects the DATA HANDLER object to implement the following methods:
Each method gets the SXC object as the first argument, and the data as the second argument: worksheet gets the name of the worksheet, workbook gets the filename of the SXC file, and row receives a list reference to all the cells in that row.
The interesting callback is the row() function, and often it's the only
function of any interest. If you want to avoid creating a class and just
want to implement a row() callback, you can do something like this:
sub Whatever::row {
my($self, $SXC, $row_data) = @_;
print join(",", map { csv_quote( $_ ) } @$row_data ),"\n";
}
sub Whatever::worksheet {}
sub Whatever::workbook {}
$SXC->set_data_handler( bless {}, "Whatever" );
$SXC->parse_file( ... );
Desmond Lee <deslee@shaw.ca>
|
OpenOffice::Parse::SXC - Perl extension for parsing OpenOffice SXC files |