From 0318aee523bf86bedc323234fc041b566625b372 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 15 Mar 2015 01:44:53 -0400 Subject: don't assume all of these elements exist (#29) apparently google docs doesn't generate a bunch of stuff --- lib/Spreadsheet/ParseXLSX.pm | 31 +++++++++++++++++++------------ t/bug-29.t | 11 +++++++++++ t/data/bug-29.xlsx | Bin 0 -> 3761 bytes 3 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 t/bug-29.t create mode 100644 t/data/bug-29.xlsx diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm index f1193e7..97bff38 100644 --- a/lib/Spreadsheet/ParseXLSX.pm +++ b/lib/Spreadsheet/ParseXLSX.pm @@ -508,20 +508,25 @@ sub _parse_styles { $v = 0 if $v eq 'false'; $v } qw(diagonalDown diagonalUp); + my %borderstyles = map { + my $e = $border->first_child($_); + $_ => ($e ? $e->att('style') || 'none' : 'none') + } qw(left right top bottom diagonal); + my %bordercolors = map { + my $e = $border->first_child($_); + $_ => ($e ? $e->first_child('color') : undef) + } qw(left right top bottom diagonal); # XXX specs say "begin" and "end" rather than "left" and "right", # but... that's not what seems to be in the file itself (sigh) { colors => [ map { - $self->_color( - $workbook->{Color}, - $border->first_child($_)->first_child('color') - ) + $self->_color($workbook->{Color}, $bordercolors{$_}) } qw(left right top bottom) ], styles => [ map { - $border{$border->first_child($_)->att('style') || 'none'} + $border{$borderstyles{$_}} } qw(left right top bottom) ], diagonal => [ @@ -529,11 +534,8 @@ sub _parse_styles { : $ddiag && !$udiag ? 2 : !$ddiag && $udiag ? 1 : 0), - $border{$border->first_child('diagonal')->att('style') || 'none'}, - $self->_color( - $workbook->{Color}, - $border->first_child('diagonal')->first_child('color') - ), + $border{$borderstyles{diagonal}}, + $self->_color($workbook->{Color}, $bordercolors{diagonal}), ], } } $styles->find_nodes('//borders/border'); @@ -581,8 +583,13 @@ sub _parse_styles { my @font = map { my $vert = $_->first_child('vertAlign'); my $under = $_->first_child('u'); + my $heightelem = $_->first_child('sz'); + # XXX i guess 12 is okay? + my $height = 0+($heightelem ? $heightelem->att('val') : 12); + my $nameelem = $_->first_child('name'); + my $name = $nameelem ? $nameelem->att('val') : ''; Spreadsheet::ParseExcel::Font->new( - Height => 0+$_->first_child('sz')->att('val'), + Height => $height, # Attr => $iAttr, # XXX not sure if there's a better way to keep the indexing stuff # intact rather than just going straight to #xxxxxx @@ -614,7 +621,7 @@ sub _parse_styles { : 0) : 0 ), - Name => $_->first_child('name')->att('val'), + Name => $name, Bold => $_->has_child('b') ? 1 : 0, Italic => $_->has_child('i') ? 1 : 0, diff --git a/t/bug-29.t b/t/bug-29.t new file mode 100644 index 0000000..19ef592 --- /dev/null +++ b/t/bug-29.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-29.xlsx'); +pass('it parses successfully'); + +done_testing; diff --git a/t/data/bug-29.xlsx b/t/data/bug-29.xlsx new file mode 100644 index 0000000..0e05e8b Binary files /dev/null and b/t/data/bug-29.xlsx differ -- cgit v1.2.3-54-g00ecf