summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-05-09 11:59:27 -0500
committerJesse Luehrs <doy@tozt.net>2013-05-09 11:59:27 -0500
commit774f70b10b1ef50a0a03799fea656cc993a7fb77 (patch)
tree175df409b00ec42fe11e85efd5e6885d21e1ac00
parent91752721b10639b4ae49c33c48e0f18ba0cc36e9 (diff)
downloadspreadsheet-template-774f70b10b1ef50a0a03799fea656cc993a7fb77.tar.gz
spreadsheet-template-774f70b10b1ef50a0a03799fea656cc993a7fb77.zip
move this fixup to where the rest of the fixups are done
-rw-r--r--lib/Spreadsheet/Template/Generator/Parser/Excel.pm8
-rw-r--r--lib/Spreadsheet/Template/Generator/Parser/XLSX.pm37
2 files changed, 23 insertions, 22 deletions
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) = @_;