summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-12-09 15:05:26 -0500
committerJesse Luehrs <doy@tozt.net>2013-12-09 15:19:32 -0500
commit176c2e79f2704af024e02d755b3dbb714ba72a70 (patch)
tree55484c21c51415c9600820f0c1f057820ffd44fc
parentdf3388718f93afb099833d78cdbfdd644ebec594 (diff)
downloadspreadsheet-parsexlsx-176c2e79f2704af024e02d755b3dbb714ba72a70.tar.gz
spreadsheet-parsexlsx-176c2e79f2704af024e02d755b3dbb714ba72a70.zip
support more font properties (#14)
-rw-r--r--lib/Spreadsheet/ParseXLSX.pm27
-rw-r--r--t/bug-14.t35
-rw-r--r--t/data/bug-14.xlsxbin0 -> 5005 bytes
3 files changed, 58 insertions, 4 deletions
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 <u/> 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
--- /dev/null
+++ b/t/data/bug-14.xlsx
Binary files differ