summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2015-03-15 01:44:53 -0400
committerJesse Luehrs <doy@tozt.net>2015-03-15 01:45:52 -0400
commit0318aee523bf86bedc323234fc041b566625b372 (patch)
tree5bfde550b0edbd032a7686c06887fb12d7c957f7
parentd67c41ec9b8f2008114975dcb1530ab294b11cfb (diff)
downloadspreadsheet-parsexlsx-0318aee523bf86bedc323234fc041b566625b372.tar.gz
spreadsheet-parsexlsx-0318aee523bf86bedc323234fc041b566625b372.zip
don't assume all of these elements exist (#29)
apparently google docs doesn't generate a bunch of stuff
-rw-r--r--lib/Spreadsheet/ParseXLSX.pm31
-rw-r--r--t/bug-29.t11
-rw-r--r--t/data/bug-29.xlsxbin0 -> 3761 bytes
3 files changed, 30 insertions, 12 deletions
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
--- /dev/null
+++ b/t/data/bug-29.xlsx
Binary files differ