summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-09-16 23:35:00 -0400
committerJesse Luehrs <doy@tozt.net>2013-09-16 23:35:00 -0400
commit90ca90b8e8f2dafc2befb8c5ddba1eea8e4eebf3 (patch)
treefc893aaaaf3fdca335ae99ee5cdcf84b693310d0
parent184bd929cdd7059c5387c2e753ab63731020d537 (diff)
downloadspreadsheet-parsexlsx-90ca90b8e8f2dafc2befb8c5ddba1eea8e4eebf3.tar.gz
spreadsheet-parsexlsx-90ca90b8e8f2dafc2befb8c5ddba1eea8e4eebf3.zip
fix row and column range for empty sheets (fixes #8)
-rw-r--r--lib/Spreadsheet/ParseXLSX.pm30
-rw-r--r--t/bug-8.t19
-rw-r--r--t/data/bug-8.xlsxbin0 -> 8639 bytes
3 files changed, 39 insertions, 10 deletions
diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm
index a7db72b..0dca08a 100644
--- a/lib/Spreadsheet/ParseXLSX.pm
+++ b/lib/Spreadsheet/ParseXLSX.pm
@@ -126,18 +126,28 @@ sub _parse_sheet {
my $self = shift;
my ($sheet, $sheet_xml) = @_;
- # XXX need a fallback here, the dimension tag is optional
- my ($dimension) = $sheet_xml->find_nodes('//dimension');
- my ($rmin, $cmin, $rmax, $cmax) = $self->_dimensions(
- $dimension->att('ref')
- );
+ my @cells = $sheet_xml->find_nodes('//sheetData/row/c');
+
+ if (@cells) {
+ # XXX need a fallback here, the dimension tag is optional
+ my ($dimension) = $sheet_xml->find_nodes('//dimension');
+ my ($rmin, $cmin, $rmax, $cmax) = $self->_dimensions(
+ $dimension->att('ref')
+ );
- $sheet->{MinRow} = $rmin;
- $sheet->{MinCol} = $cmin;
- $sheet->{MaxRow} = $rmax;
- $sheet->{MaxCol} = $cmax;
+ $sheet->{MinRow} = $rmin;
+ $sheet->{MinCol} = $cmin;
+ $sheet->{MaxRow} = $rmax;
+ $sheet->{MaxCol} = $cmax;
+ }
+ else {
+ $sheet->{MinRow} = 0;
+ $sheet->{MinCol} = 0;
+ $sheet->{MaxRow} = -1;
+ $sheet->{MaxCol} = -1;
+ }
- for my $cell ($sheet_xml->find_nodes('//sheetData/row/c')) {
+ for my $cell (@cells) {
my ($row, $col) = $self->_cell_to_row_col($cell->att('r'));
my $val = $cell->first_child('v')
? $cell->first_child('v')->text
diff --git a/t/bug-8.t b/t/bug-8.t
new file mode 100644
index 0000000..45dad0d
--- /dev/null
+++ b/t/bug-8.t
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+use Spreadsheet::ParseXLSX;
+
+my $wb = Spreadsheet::ParseXLSX->new->parse('t/data/bug-7.xlsx');
+is($wb->worksheet_count, 3);
+
+my $ws = $wb->worksheet(2);
+my ($rmin, $rmax) = $ws->row_range;
+my ($cmin, $cmax) = $ws->col_range;
+is($rmin, 0);
+is($rmax, -1);
+is($cmin, 0);
+is($cmax, -1);
+
+done_testing;
diff --git a/t/data/bug-8.xlsx b/t/data/bug-8.xlsx
new file mode 100644
index 0000000..c516813
--- /dev/null
+++ b/t/data/bug-8.xlsx
Binary files differ