summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2016-08-16 03:08:25 -0400
committerJesse Luehrs <doy@tozt.net>2016-08-16 03:09:53 -0400
commit80198923186bedda61d4dceb0272210dc8bec533 (patch)
treee7926db1cdce6f0b110c3265536d38b1c32e9f2f
parenteb63a78baa763b463f6975143d7a3d63c4fe1e75 (diff)
downloadspreadsheet-parsexlsx-80198923186bedda61d4dceb0272210dc8bec533.tar.gz
spreadsheet-parsexlsx-80198923186bedda61d4dceb0272210dc8bec533.zip
handle cell data without explicit location data (#61)
apparently this is a thing sometimes?
-rw-r--r--Changes2
-rw-r--r--lib/Spreadsheet/ParseXLSX.pm31
-rw-r--r--t/bug-61.t11
-rw-r--r--t/data/bug-61.xlsxbin0 -> 90974 bytes
4 files changed, 34 insertions, 10 deletions
diff --git a/Changes b/Changes
index 452c2b1..d7bfb11 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,8 @@
Revision history for Spreadsheet-ParseXLSX
{{$NEXT}}
+ - Fix issues parsing sheets whose cell elements do not have location
+ attributes (dgiordano, #61)
0.26 2016-08-16
- Add explicit dependency on perl 5.10 (we apparently broke 5.8 support
diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm
index fac59ba..5df5111 100644
--- a/lib/Spreadsheet/ParseXLSX.pm
+++ b/lib/Spreadsheet/ParseXLSX.pm
@@ -224,6 +224,7 @@ sub _parse_sheet {
my $default_column_width = 10;
my %cells;
+ my $row_idx = 0;
my $sheet_xml = $self->_new_twig(
twig_roots => {
@@ -331,15 +332,6 @@ sub _parse_sheet {
$twig->purge;
},
- 's:row' => sub {
- my ( $twig, $row ) = @_;
-
- $row_heights[ $row->att('r') - 1 ] = $row->att('ht');
- $rows_hidden[ $row->att('r') - 1 ] = $self->_xml_boolean($row->att('hidden'));
-
- $twig->purge;
- },
-
's:selection' => sub {
my ( $twig, $selection ) = @_;
@@ -367,9 +359,26 @@ sub _parse_sheet {
's:sheetData/s:row' => sub {
my ( $twig, $row_elt ) = @_;
+ my $explicit_row_idx = $row_elt->att('r');
+ $row_idx = $explicit_row_idx - 1 if defined $explicit_row_idx;
+ $row_heights[$row_idx] = $row_elt->att('ht');
+ $rows_hidden[$row_idx] = $self->_xml_boolean($row_elt->att('hidden'));
+
+ my $col_idx = 0;
for my $cell ( $row_elt->children('s:c') ){
- my ($row, $col) = $self->_cell_to_row_col($cell->att('r'));
+ my $loc = $cell->att('r');
+ my ($row, $col);
+ if ($loc) {
+ ($row, $col) = $self->_cell_to_row_col($loc);
+ if ($row != $row_idx) {
+ warn "mismatched coords: got $loc for cell in row $row_idx";
+ }
+ $col_idx = $col - 1;
+ }
+ else {
+ ($row, $col) = ($row_idx, $col_idx);
+ }
$sheet->{MaxRow} = $row
if $sheet->{MaxRow} < $row;
$sheet->{MaxCol} = $col
@@ -444,9 +453,11 @@ sub _parse_sheet {
);
$cells{"$row;$col"} = $cell;
$sheet->{Cells}[$row][$col] = $cell;
+ $col_idx++;
}
$twig->purge;
+ $row_idx++;
},
}
);
diff --git a/t/bug-61.t b/t/bug-61.t
new file mode 100644
index 0000000..72f8af4
--- /dev/null
+++ b/t/bug-61.t
@@ -0,0 +1,11 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+use Spreadsheet::ParseXLSX;
+
+my $wb = Spreadsheet::ParseXLSX->new->parse('t/data/bug-61.xlsx');
+pass('it parses successfully');
+
+done_testing;
diff --git a/t/data/bug-61.xlsx b/t/data/bug-61.xlsx
new file mode 100644
index 0000000..82f791b
--- /dev/null
+++ b/t/data/bug-61.xlsx
Binary files differ