From 8a787698efd28a9bec64b1e5d13a4670b1bc1779 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 29 Jul 2013 19:15:48 -0400 Subject: fix spreadsheets that have only a single cell (#2) --- lib/Spreadsheet/ParseXLSX.pm | 19 ++++++++++++++++--- t/bug-2.t | 22 ++++++++++++++++++++++ t/data/bug-2.xlsx | Bin 0 -> 8748 bytes 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 t/bug-2.t create mode 100644 t/data/bug-2.xlsx 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 Binary files /dev/null and b/t/data/bug-2.xlsx differ -- cgit v1.2.3-54-g00ecf