summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-05-01 12:25:42 -0500
committerJesse Luehrs <doy@tozt.net>2013-05-01 12:30:20 -0500
commit9cf7419380a812d1bbacb74018c111a7e77cb5ac (patch)
tree8bba295fd364c81a5f8cd0b30cbba483877d3adf
parent9824fd56633cc3cf4b65aa5c1585805e6fc447f3 (diff)
downloadspreadsheet-template-9cf7419380a812d1bbacb74018c111a7e77cb5ac.tar.gz
spreadsheet-template-9cf7419380a812d1bbacb74018c111a7e77cb5ac.zip
handle types a bit better
-rw-r--r--lib/Spreadsheet/Template/Generator/Parser/Excel.pm30
-rw-r--r--lib/Spreadsheet/Template/Generator/Parser/XLSX.pm14
2 files changed, 39 insertions, 5 deletions
diff --git a/lib/Spreadsheet/Template/Generator/Parser/Excel.pm b/lib/Spreadsheet/Template/Generator/Parser/Excel.pm
index 4638a8b..1aed4a8 100644
--- a/lib/Spreadsheet/Template/Generator/Parser/Excel.pm
+++ b/lib/Spreadsheet/Template/Generator/Parser/Excel.pm
@@ -72,10 +72,36 @@ sub _parse_cell {
my $self = shift;
my ($cell) = @_;
+ my %types = (
+ 'Numeric' => 'number',
+ 'Text' => 'string',
+ 'Date' => 'date_time',
+ );
+
+ my $contents = $cell->unformatted;
+ my $type = $cell->type;
+
+ if ($type eq 'Numeric') {
+ $type = 'number';
+ }
+ elsif ($type eq 'Text') {
+ if ($contents =~ /^=/) {
+ $type = 'formula';
+ }
+ else {
+ $type = 'string';
+ }
+ }
+ elsif ($type eq 'Date') {
+ $type = 'date_time';
+ }
+ else {
+ die "unknown type $type";
+ }
my $data = {
- contents => $self->_filter_cell_contents($cell->unformatted),
- type => $cell->type,
+ contents => $self->_filter_cell_contents($contents, $type),
+ type => $type,
};
return $data;
diff --git a/lib/Spreadsheet/Template/Generator/Parser/XLSX.pm b/lib/Spreadsheet/Template/Generator/Parser/XLSX.pm
index 8e3c29c..75f8481 100644
--- a/lib/Spreadsheet/Template/Generator/Parser/XLSX.pm
+++ b/lib/Spreadsheet/Template/Generator/Parser/XLSX.pm
@@ -12,11 +12,19 @@ sub make_excel {
return Spreadsheet::XLSX->new($filename);
}
+# 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) = @_;
- # XXX this decode call really feels like a bug in Spreadsheet::XLSX
- return XML::Entities::decode('all', $contents);
+ my ($contents, $type) = @_;
+
+ $contents = XML::Entities::decode('all', $contents);
+
+ if ($type eq 'number') {
+ $contents = 0+$contents;
+ }
+
+ return $contents;
}
__PACKAGE__->meta->make_immutable;