Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TabColor and ColFmtNo support to ParseXLSX #26

Merged
merged 2 commits into from Jul 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/Spreadsheet/ParseXLSX.pm
Expand Up @@ -136,6 +136,7 @@ sub _parse_sheet {


my @merged_cells; my @merged_cells;


my @column_formats;
my @column_widths; my @column_widths;
my @row_heights; my @row_heights;


Expand Down Expand Up @@ -195,8 +196,10 @@ sub _parse_sheet {
'col' => sub { 'col' => sub {
my ( $twig, $col ) = @_; my ( $twig, $col ) = @_;


$column_widths[ $_ - 1 ] = $col->att('width') for my $colnum ($col->att('min')..$col->att('max')) {
for ( $col->att('min') .. $col->att('max') ); $column_widths[$colnum - 1] = $col->att('width');
$column_formats[$colnum - 1] = $col->att('style');
}


$twig->purge; $twig->purge;
}, },
Expand Down Expand Up @@ -226,6 +229,14 @@ sub _parse_sheet {
$twig->purge; $twig->purge;
}, },


'sheetPr/tabColor' => sub {
my ( $twig, $tab_color ) = @_;

$sheet->{TabColor} = $self->_color($sheet->{_Book}{Color}, $tab_color);

$twig->purge;
},

} }
); );


Expand Down Expand Up @@ -326,6 +337,7 @@ sub _parse_sheet {
$sheet->{ColWidth} = [ $sheet->{ColWidth} = [
map { defined $_ ? 0+$_ : 0+$default_column_width } @column_widths map { defined $_ ? 0+$_ : 0+$default_column_width } @column_widths
]; ];
$sheet->{ColFmtNo} = \@column_formats;


} }


Expand Down
25 changes: 25 additions & 0 deletions 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;
Binary file added t/data/column-formats.xlsx
Binary file not shown.
Binary file added t/data/tab-color.xlsx
Binary file not shown.
15 changes: 15 additions & 0 deletions 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;