From 774f70b10b1ef50a0a03799fea656cc993a7fb77 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 9 May 2013 11:59:27 -0500 Subject: move this fixup to where the rest of the fixups are done --- lib/Spreadsheet/Template/Generator/Parser/Excel.pm | 8 +---- lib/Spreadsheet/Template/Generator/Parser/XLSX.pm | 37 +++++++++++++--------- 2 files changed, 23 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/lib/Spreadsheet/Template/Generator/Parser/Excel.pm b/lib/Spreadsheet/Template/Generator/Parser/Excel.pm index 822b35b..e4bf47a 100644 --- a/lib/Spreadsheet/Template/Generator/Parser/Excel.pm +++ b/lib/Spreadsheet/Template/Generator/Parser/Excel.pm @@ -154,7 +154,7 @@ sub _parse_cell { } my $data = { - contents => $self->_filter_cell_contents($contents, $type), + contents => $contents, type => $type, ($formula ? (formula => $formula) : ()), (keys %$format_data ? (format => $format_data) : ()), @@ -163,12 +163,6 @@ sub _parse_cell { return $data; } -sub _filter_cell_contents { - my $self = shift; - my ($contents) = @_; - return $contents; -} - no Moose::Role; 1; diff --git a/lib/Spreadsheet/Template/Generator/Parser/XLSX.pm b/lib/Spreadsheet/Template/Generator/Parser/XLSX.pm index bacaabd..aa7317d 100644 --- a/lib/Spreadsheet/Template/Generator/Parser/XLSX.pm +++ b/lib/Spreadsheet/Template/Generator/Parser/XLSX.pm @@ -29,6 +29,7 @@ sub _fixup_excel { for my $sheet ($excel->worksheets) { my $sheet_xml = $self->_parse_xml("xl/$sheet->{path}"); + $self->_fixup_cell_contents($sheet); $self->_parse_cell_sizes($sheet, $sheet_xml->root); $self->_parse_formulas($sheet, $sheet_xml->root); $self->_parse_sheet_selection($sheet, $sheet_xml->root); @@ -213,6 +214,27 @@ sub _parse_styles { } } +sub _fixup_cell_contents { + my $self = shift; + my ($sheet) = @_; + + my ($rmin, $rmax) = $sheet->row_range; + my ($cmin, $cmax) = $sheet->col_range; + + # XXX these are just bugs in Spreadsheet::XLSX since it "parses" the xml + # with regexes + for my $row ($rmin..$rmax) { + for my $col ($cmin..$cmax) { + my $cell = $sheet->get_cell($row, $col); + $cell->{Val} = XML::Entities::decode('all', $cell->{Val}); + $cell->{_Value} = XML::Entities::decode('all', $cell->{_Value}); + if ($cell->{Type} && $cell->{Type} eq 'Numeric') { + $cell->{Val} = 0+$cell->{Val}; + } + } + } +} + sub _parse_cell_sizes { my $self = shift; my ($sheet, $root) = @_; @@ -308,21 +330,6 @@ sub _cell_to_row_col { return ($row, $col); } -# XXX this stuff all feels like working around bugs in Spreadsheet::XLSX - -# maybe look into that at some point -sub _filter_cell_contents { - my $self = shift; - my ($contents, $type) = @_; - - $contents = XML::Entities::decode('all', $contents); - - if ($type eq 'number') { - $contents = 0+$contents; - } - - return $contents; -} - sub _color { my $self = shift; my ($colors, $color_node) = @_; -- cgit v1.2.3-54-g00ecf