From 176c2e79f2704af024e02d755b3dbb714ba72a70 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 9 Dec 2013 15:05:26 -0500 Subject: support more font properties (#14) --- lib/Spreadsheet/ParseXLSX.pm | 27 +++++++++++++++++++++++---- t/bug-14.t | 35 +++++++++++++++++++++++++++++++++++ t/data/bug-14.xlsx | Bin 0 -> 5005 bytes 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 t/bug-14.t create mode 100644 t/data/bug-14.xlsx diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm index 381b16c..0c021c3 100644 --- a/lib/Spreadsheet/ParseXLSX.pm +++ b/lib/Spreadsheet/ParseXLSX.pm @@ -454,6 +454,8 @@ sub _parse_styles { ); my @font = map { + my $vert = $_->first_child('vertAlign'); + my $under = $_->first_child('u'); Spreadsheet::ParseExcel::Font->new( Height => 0+$_->first_child('sz')->att('val'), # Attr => $iAttr, @@ -468,14 +470,31 @@ sub _parse_styles { ) : '#000000' ), - # Super => $iSuper, - # UnderlineStyle => $iUnderline, + Super => ($vert + ? ($vert->att('val') eq 'superscript' ? 1 + : $vert->att('val') eq 'subscript' ? 2 + : 0) + : 0 + ), + # XXX not sure what the single accounting and double accounting + # underline styles map to in xlsx. also need to map the new + # underline styles + UnderlineStyle => ($under + # XXX sometimes style xml files can contain just with no + # val attribute. i think this means single underline, but not + # sure + ? (!$under->att('val') ? 1 + : $under->att('val') eq 'single' ? 1 + : $under->att('val') eq 'double' ? 2 + : 0) + : 0 + ), Name => $_->first_child('name')->att('val'), Bold => $_->has_child('b') ? 1 : 0, Italic => $_->has_child('i') ? 1 : 0, - # Underline => $bUnderline, - # Strikeout => $bStrikeout, + Underline => $_->has_child('u') ? 1 : 0, + Strikeout => $_->has_child('strike') ? 1 : 0, ) } $styles->find_nodes('//fonts/font'); diff --git a/t/bug-14.t b/t/bug-14.t new file mode 100644 index 0000000..3237b0b --- /dev/null +++ b/t/bug-14.t @@ -0,0 +1,35 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +use Spreadsheet::ParseXLSX; + +my $wb = Spreadsheet::ParseXLSX->new->parse('t/data/bug-14.xlsx'); +my $ws = $wb->worksheet(0); + +for my $row (0..6) { + for my $col ($row..6) { + next if $row == 5 && $col == 6; + + my $font = $ws->get_cell($row, $col)->get_format->{Font}; + is($font->{Name}, 'Arial'); + is(!!$font->{Bold}, $row == 1 || $col == 1); + is(!!$font->{Italic}, $row == 2 || $col == 2); + is($font->{Height}, 10); + is(!!$font->{Underline}, $row == 3 || $col == 3); + if ($row == 3 || $col == 3) { + is($font->{UnderlineStyle}, 1); + } + is($font->{Color}, '#000000'); + is(!!$font->{Strikeout}, $row == 4 || $col == 4); + is( + $font->{Super}, + $row == 5 || $col == 5 ? 2 + : $row == 6 || $col == 6 ? 1 + : 0 + ); + } +} + +done_testing; diff --git a/t/data/bug-14.xlsx b/t/data/bug-14.xlsx new file mode 100644 index 0000000..7dfa004 Binary files /dev/null and b/t/data/bug-14.xlsx differ -- cgit v1.2.3-54-g00ecf