diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-07-05 14:35:08 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-07-05 14:35:08 -0400 |
commit | 01f97f6374de81f99aaecdf593615a9d334781da (patch) | |
tree | a96a907e4a013a9d90168b732ef8a102f3c3123a | |
parent | 063a3ed5650df0e84af5ddfc3c909077d04159d5 (diff) | |
parent | c4c84e8055f67738d0f9b6ae30d1d844c6fc46a4 (diff) | |
download | spreadsheet-parsexlsx-01f97f6374de81f99aaecdf593615a9d334781da.tar.gz spreadsheet-parsexlsx-01f97f6374de81f99aaecdf593615a9d334781da.zip |
Merge pull request #26 from felliott/parseexcel-parity
Add TabColor and ColFmtNo support to ParseXLSX
-rw-r--r-- | lib/Spreadsheet/ParseXLSX.pm | 16 | ||||
-rw-r--r-- | t/column-formats.t | 25 | ||||
-rw-r--r-- | t/data/column-formats.xlsx | bin | 0 -> 25979 bytes | |||
-rw-r--r-- | t/data/tab-color.xlsx | bin | 0 -> 27087 bytes | |||
-rw-r--r-- | t/tab-color.t | 15 |
5 files changed, 54 insertions, 2 deletions
diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm index 99d3c33..264ead6 100644 --- a/lib/Spreadsheet/ParseXLSX.pm +++ b/lib/Spreadsheet/ParseXLSX.pm @@ -137,6 +137,7 @@ sub _parse_sheet { my @merged_cells; + my @column_formats; my @column_widths; my @row_heights; @@ -196,8 +197,10 @@ sub _parse_sheet { 'col' => sub { my ( $twig, $col ) = @_; - $column_widths[ $_ - 1 ] = $col->att('width') - for ( $col->att('min') .. $col->att('max') ); + for my $colnum ($col->att('min')..$col->att('max')) { + $column_widths[$colnum - 1] = $col->att('width'); + $column_formats[$colnum - 1] = $col->att('style'); + } $twig->purge; }, @@ -227,6 +230,14 @@ sub _parse_sheet { $twig->purge; }, + 'sheetPr/tabColor' => sub { + my ( $twig, $tab_color ) = @_; + + $sheet->{TabColor} = $self->_color($sheet->{_Book}{Color}, $tab_color); + + $twig->purge; + }, + } ); @@ -327,6 +338,7 @@ sub _parse_sheet { $sheet->{ColWidth} = [ map { defined $_ ? 0+$_ : 0+$default_column_width } @column_widths ]; + $sheet->{ColFmtNo} = \@column_formats; } diff --git a/t/column-formats.t b/t/column-formats.t new file mode 100644 index 0000000..7ce9650 --- /dev/null +++ b/t/column-formats.t @@ -0,0 +1,25 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +use Spreadsheet::ParseXLSX; + +my $wb = Spreadsheet::ParseXLSX->new->parse('t/data/column-formats.xlsx'); +my $ws = $wb->worksheet(0); + +ok(my $col_format_nos = $ws->{ColFmtNo}); + +my @col_formats = map { $wb->{Format}[ $_ ] } @$col_format_nos; +is_deeply($col_formats[0]->{Fill}, [1, '#FF0000', '#FFFFFF']); + +is($col_formats[1]->{AlignH}, 3); +is($col_formats[1]->{AlignV}, 0); + +my $font = $col_formats[2]->{Font}; +is_deeply($font->{Name}, 'Arial'); +is_deeply($font->{Height}, 16); +is_deeply($font->{Bold}, 1); + + +done_testing; diff --git a/t/data/column-formats.xlsx b/t/data/column-formats.xlsx Binary files differnew file mode 100644 index 0000000..a1a9344 --- /dev/null +++ b/t/data/column-formats.xlsx diff --git a/t/data/tab-color.xlsx b/t/data/tab-color.xlsx Binary files differnew file mode 100644 index 0000000..7061e84 --- /dev/null +++ b/t/data/tab-color.xlsx diff --git a/t/tab-color.t b/t/tab-color.t new file mode 100644 index 0000000..ef1ab49 --- /dev/null +++ b/t/tab-color.t @@ -0,0 +1,15 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +use Spreadsheet::ParseXLSX; + +my $wb = Spreadsheet::ParseXLSX->new->parse('t/data/tab-color.xlsx'); +my $ws1 = $wb->worksheet(0); +is($ws1->get_tab_color, '#FF0000'); + +my $ws2 = $wb->worksheet(1); +is($ws2->get_tab_color, undef); + +done_testing; |