From 9615cc04a2c9d8fc40d04ecade75b23ec2f05d19 Mon Sep 17 00:00:00 2001 From: rdboisvert Date: Wed, 6 Aug 2014 10:20:26 -0400 Subject: Adjustments to support undefined values created by JasperSoft --- lib/Spreadsheet/ParseXLSX.pm | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm index 082228a..cec1c8c 100644 --- a/lib/Spreadsheet/ParseXLSX.pm +++ b/lib/Spreadsheet/ParseXLSX.pm @@ -121,7 +121,7 @@ sub _parse_workbook { $workbook->{SheetCount} = scalar(@sheets); my ($node) = $files->{workbook}->find_nodes('//workbookView'); - my $selected = $node->att('activeTab'); + my $selected = $node ? $node->att('activeTab') : undef; $workbook->{SelectedSheet} = defined($selected) ? 0+$selected : 0; return $workbook; @@ -158,8 +158,8 @@ sub _parse_sheet { $sheet->{MinRow} = $rmin; $sheet->{MinCol} = $cmin; - $sheet->{MaxRow} = $rmax; - $sheet->{MaxCol} = $cmax; + $sheet->{MaxRow} = $rmax ? $rmax : -1; + $sheet->{MaxCol} = $cmax ? $cmax : -1; $twig->purge; }, @@ -255,10 +255,18 @@ sub _parse_sheet { for my $cell ( $row_elt->children('c') ){ my ($row, $col) = $self->_cell_to_row_col($cell->att('r')); + $sheet->{MaxRow} = $row; + $sheet->{MaxCol} = $col; my $type = $cell->att('t') || 'n'; - my $val_xml = $type eq 'inlineStr' - ? $cell->first_child('is')->first_child('t') - : $cell->first_child('v'); + my $val_xml; + if ($type ne 'inlineStr') { + $val_xml = $cell->first_child('v'); + } elsif (defined $cell->first_child('is')) { + foreach my $tnode ($cell->find_nodes ('.//t')) { + $val_xml = $tnode; + last; + } + } my $val = $val_xml ? $val_xml->text : undef; my $long_type; @@ -769,7 +777,10 @@ sub _color { $color = '#' . substr($color_node->att('rgb'), 2, 6); } elsif (defined $color_node->att('theme')) { - $color = '#' . $colors->[$color_node->att('theme')]; + my $theme = $colors->[$color_node->att('theme')]; + if (defined $theme) { + $color = '#' . $colors->[$color_node->att('theme')]; + } } $color = $self->_apply_tint($color, $color_node->att('tint')) -- cgit v1.2.3-54-g00ecf From f0e814f4120bde95fe38e271114c49b07ae10b2e Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Oct 2014 14:56:04 -0400 Subject: Fixed bug when last column shorter than normal --- lib/Spreadsheet/ParseXLSX.pm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm index cec1c8c..615835e 100644 --- a/lib/Spreadsheet/ParseXLSX.pm +++ b/lib/Spreadsheet/ParseXLSX.pm @@ -255,8 +255,12 @@ sub _parse_sheet { for my $cell ( $row_elt->children('c') ){ my ($row, $col) = $self->_cell_to_row_col($cell->att('r')); - $sheet->{MaxRow} = $row; - $sheet->{MaxCol} = $col; + if ($sheet->{MaxRow} < $row) { + $sheet->{MaxRow} = $row; + } + if ($sheet->{MaxCol} < $col) { + $sheet->{MaxCol} = $col; + } my $type = $cell->att('t') || 'n'; my $val_xml; if ($type ne 'inlineStr') { -- cgit v1.2.3-54-g00ecf From f32d2416c228eeafedcd7d77178c74efdc7e3884 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 15 Mar 2015 01:14:11 -0400 Subject: cleanups --- lib/Spreadsheet/ParseXLSX.pm | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm index 615835e..26269fd 100644 --- a/lib/Spreadsheet/ParseXLSX.pm +++ b/lib/Spreadsheet/ParseXLSX.pm @@ -255,21 +255,17 @@ sub _parse_sheet { for my $cell ( $row_elt->children('c') ){ my ($row, $col) = $self->_cell_to_row_col($cell->att('r')); - if ($sheet->{MaxRow} < $row) { - $sheet->{MaxRow} = $row; - } - if ($sheet->{MaxCol} < $col) { - $sheet->{MaxCol} = $col; - } + $sheet->{MaxRow} = $row + if $sheet->{MaxRow} < $row; + $sheet->{MaxCol} = $col + if $sheet->{MaxCol} < $col; my $type = $cell->att('t') || 'n'; my $val_xml; if ($type ne 'inlineStr') { - $val_xml = $cell->first_child('v'); - } elsif (defined $cell->first_child('is')) { - foreach my $tnode ($cell->find_nodes ('.//t')) { - $val_xml = $tnode; - last; - } + $val_xml = $cell->first_child('v'); + } + elsif (defined $cell->first_child('is')) { + $val_xml = ($cell->find_nodes('.//t'))[0]; } my $val = $val_xml ? $val_xml->text : undef; @@ -783,7 +779,10 @@ sub _color { elsif (defined $color_node->att('theme')) { my $theme = $colors->[$color_node->att('theme')]; if (defined $theme) { - $color = '#' . $colors->[$color_node->att('theme')]; + $color = "#$theme"; + } + else { + return; } } -- cgit v1.2.3-54-g00ecf