summaryrefslogtreecommitdiffstats
path: root/lib/Spreadsheet/Template/Generator/Parser/XLSX.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Spreadsheet/Template/Generator/Parser/XLSX.pm')
-rw-r--r--lib/Spreadsheet/Template/Generator/Parser/XLSX.pm80
1 files changed, 8 insertions, 72 deletions
diff --git a/lib/Spreadsheet/Template/Generator/Parser/XLSX.pm b/lib/Spreadsheet/Template/Generator/Parser/XLSX.pm
index b542ac3..8e3c29c 100644
--- a/lib/Spreadsheet/Template/Generator/Parser/XLSX.pm
+++ b/lib/Spreadsheet/Template/Generator/Parser/XLSX.pm
@@ -1,86 +1,22 @@
package Spreadsheet::Template::Generator::Parser::XLSX;
use Moose;
-use XML::Entities;
use Spreadsheet::XLSX;
+use XML::Entities;
-with 'Spreadsheet::Template::Generator::Parser';
+with 'Spreadsheet::Template::Generator::Parser::Excel';
-sub parse {
+sub make_excel {
my $self = shift;
my ($filename) = @_;
-
- my $excel = Spreadsheet::XLSX->new($filename);
- return $self->_parse_workbook($excel);
- my $data = {
- worksheets => [],
- };
- for my $sheet ($excel->worksheets) {
- push @{ $data->{worksheets} }, $self->_parse
- }
-}
-
-sub _parse_workbook {
- my $self = shift;
- my ($excel) = @_;
-
- my $data = {
- worksheets => [],
- };
-
- for my $sheet ($excel->worksheets) {
- push @{ $data->{worksheets} }, $self->_parse_worksheet($sheet);
- }
-
- return $data;
-}
-
-sub _parse_worksheet {
- my $self = shift;
- my ($sheet) = @_;
-
- my $data = {
- cells => [],
- };
-
- my ($rmin, $rmax) = $sheet->row_range;
- my ($cmin, $cmax) = $sheet->col_range;
-
- for my $row (0..$rmin - 1) {
- push @{ $data->{cells} }, [];
- }
-
- for my $row ($rmin..$rmax) {
- my $row_data = [];
- for my $col (0..$cmin - 1) {
- push @$row_data, {};
- }
- for my $col ($cmin..$cmax) {
- if (my $cell = $sheet->get_cell($row, $col)) {
- push @$row_data, $self->_parse_cell($cell);
- }
- else {
- push @$row_data, {};
- }
- }
- push @{ $data->{cells} }, $row_data
- }
-
- return $data;
+ return Spreadsheet::XLSX->new($filename);
}
-sub _parse_cell {
+sub _filter_cell_contents {
my $self = shift;
- my ($cell) = @_;
-
-
- my $data = {
- # XXX this decode call really feels like a bug in Spreadsheet::XLSX
- contents => XML::Entities::decode('all', $cell->unformatted),
- type => $cell->type,
- };
-
- return $data;
+ my ($contents) = @_;
+ # XXX this decode call really feels like a bug in Spreadsheet::XLSX
+ return XML::Entities::decode('all', $contents);
}
__PACKAGE__->meta->make_immutable;