summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-07-29 19:15:48 -0400
committerJesse Luehrs <doy@tozt.net>2013-07-29 19:15:48 -0400
commit8a787698efd28a9bec64b1e5d13a4670b1bc1779 (patch)
treed0f37f37da1185c67a1ca092996660ee72257278
parent9b7271ba5e7628d5cbf26f603435b708575edc1c (diff)
downloadspreadsheet-parsexlsx-8a787698efd28a9bec64b1e5d13a4670b1bc1779.tar.gz
spreadsheet-parsexlsx-8a787698efd28a9bec64b1e5d13a4670b1bc1779.zip
fix spreadsheets that have only a single cell (#2)
-rw-r--r--lib/Spreadsheet/ParseXLSX.pm19
-rw-r--r--t/bug-2.t22
-rw-r--r--t/data/bug-2.xlsxbin0 -> 8748 bytes
3 files changed, 38 insertions, 3 deletions
diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm
index d96d275..055bcba 100644
--- a/lib/Spreadsheet/ParseXLSX.pm
+++ b/lib/Spreadsheet/ParseXLSX.pm
@@ -126,9 +126,9 @@ sub _parse_sheet {
# XXX need a fallback here, the dimension tag is optional
my ($dimension) = $sheet_xml->find_nodes('//dimension');
- my ($topleft, $bottomright) = split ':', $dimension->att('ref');
- my ($rmin, $cmin) = $self->_cell_to_row_col($topleft);
- my ($rmax, $cmax) = $self->_cell_to_row_col($bottomright);
+ my ($rmin, $cmin, $rmax, $cmax) = $self->_dimensions(
+ $dimension->att('ref')
+ );
$sheet->{MinRow} = $rmin;
$sheet->{MinCol} = $cmin;
@@ -552,6 +552,19 @@ sub _base_path_for {
return join('/', @path) . '/';
}
+sub _dimensions {
+ my $self = shift;
+ my ($dim) = @_;
+
+ my ($topleft, $bottomright) = split ':', $dim;
+ $bottomright = $topleft unless defined $bottomright;
+
+ my ($rmin, $cmin) = $self->_cell_to_row_col($topleft);
+ my ($rmax, $cmax) = $self->_cell_to_row_col($bottomright);
+
+ return ($rmin, $cmin, $rmax, $cmax);
+}
+
sub _cell_to_row_col {
my $self = shift;
my ($cell) = @_;
diff --git a/t/bug-2.t b/t/bug-2.t
new file mode 100644
index 0000000..0f33f40
--- /dev/null
+++ b/t/bug-2.t
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+use Spreadsheet::ParseXLSX;
+
+my $wb = Spreadsheet::ParseXLSX->new->parse('t/data/bug-2.xlsx');
+is($wb->worksheet_count, 3);
+
+my $ws = $wb->worksheet(0);
+is($ws->get_name, 'Placement');
+
+is_deeply([$ws->row_range], [0, 0]);
+is_deeply([$ws->col_range], [0, 0]);
+is_deeply($ws->{Selection}, [1, 0]);
+
+my $cell = $ws->get_cell(0, 0);
+is($cell->value, "HELLO");
+is($cell->type, 'Text');
+
+done_testing;
diff --git a/t/data/bug-2.xlsx b/t/data/bug-2.xlsx
new file mode 100644
index 0000000..c17d850
--- /dev/null
+++ b/t/data/bug-2.xlsx
Binary files differ