diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-05-13 15:21:20 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-05-13 15:21:20 -0500 |
commit | be3a6f5d87087184ac7d401725ec70ad4c947b8e (patch) | |
tree | 6c3c49dda94e33cc578087484aa9128fc02e1bc7 | |
parent | 0e5acf06cdf33c97f2c77488572ec4edfd8246a0 (diff) | |
download | spreadsheet-parsexlsx-be3a6f5d87087184ac7d401725ec70ad4c947b8e.tar.gz spreadsheet-parsexlsx-be3a6f5d87087184ac7d401725ec70ad4c947b8e.zip |
finish filling out the format stuff
-rw-r--r-- | lib/Spreadsheet/ParseXLSX.pm | 91 |
1 files changed, 81 insertions, 10 deletions
diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm index 8985657..27e8339 100644 --- a/lib/Spreadsheet/ParseXLSX.pm +++ b/lib/Spreadsheet/ParseXLSX.pm @@ -122,9 +122,9 @@ sub _parse_sheet { } $sheet->{Cells}[$row][$col] = Spreadsheet::ParseExcel::Cell->new( - Val => $val, - Type => $long_type, - # Format => ..., + Val => $val, + Type => $long_type, + Format => $sheet->{_Book}{Format}[$cell->att('s') || 0], ($cell->first_child('f') ? (Formula => $cell->first_child('f')->text) : ()), @@ -167,6 +167,64 @@ sub _parse_styles { my $self = shift; my ($workbook, $styles) = @_; + my %halign = ( + none => 0, + left => 1, + center => 2, + right => 3, + # XXX ... + ); + + my %valign = ( + top => 0, + center => 1, + bottom => 2, + # XXX ... + ); + + my %border = ( + none => 0, + thin => 5, + # XXX ... + ); + + my @fills = map { + [ + 0, # XXX + $self->_color($workbook->{Color}, $_->first_child('fgColor')), + $self->_color($workbook->{Color}, $_->first_child('bgColor')), + ] + } $styles->find_nodes('//fills/fill/patternFill'); + + my @borders = map { + my $border = $_; + # 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') + ) + } qw(left right top bottom) + ], + styles => [ + map { + $border{$border->first_child($_)->att('style') || 'none'} + } qw(left right top bottom) + ], + diagonal => [ + 0, # XXX ->att('diagonalDown') and ->att('diagonalUp') + 0, # XXX ->att('style') + $self->_color( + $workbook->{Color}, + $border->first_child('diagonal')->first_child('color') + ), + ], + } + } $styles->find_nodes('//borders/border'); + my %format_str = map { $_->att('numFmtId') => $_->att('formatCode') } $styles->find_nodes('//numFmt'); @@ -194,7 +252,14 @@ sub _parse_styles { } $styles->find_nodes('//font'); my @format = map { + my $alignment = $_->first_child('alignment'); Spreadsheet::ParseExcel::Format->new( + IgnoreFont => !$_->att('applyFont'), + IgnoreFill => !$_->att('applyFill'), + IgnoreBorder => !$_->att('applyBorder'), + IgnoreAlignment => !$_->att('applyAlignment'), + IgnoreNumberFormat => !$_->att('applyNumberFormat'), + FontNo => 0+$_->att('fontId'), Font => $font[$_->att('fontId')], FmtIdx => 0+$_->att('numFmtId'), @@ -203,9 +268,15 @@ sub _parse_styles { # Hidden => $iHidden, # Style => $iStyle, # Key123 => $i123, - # AlignH => $iAlH, - # Wrap => $iWrap, - # AlignV => $iAlV, + AlignH => $alignment + ? $halign{$alignment->att('horizontal') || 'none'} + : 0, + Wrap => $alignment + ? $alignment->att('wrapText') + : 0, + AlignV => $alignment + ? $valign{$alignment->att('vertical') || 'bottom'} + : 2, # JustLast => $iJustL, # Rotate => $iRotate, @@ -214,10 +285,10 @@ sub _parse_styles { # Merge => $iMerge, # ReadDir => $iReadDir, - # BdrStyle => [ $iBdrSL, $iBdrSR, $iBdrST, $iBdrSB ], - # BdrColor => [ $iBdrCL, $iBdrCR, $iBdrCT, $iBdrCB ], - # BdrDiag => [ $iBdrD, $iBdrSD, $iBdrCD ], - # Fill => [ $iFillP, $iFillCF, $iFillCB ], + BdrStyle => $borders[$_->att('borderId')]{styles}, + BdrColor => $borders[$_->att('borderId')]{colors}, + BdrDiag => $borders[$_->att('borderId')]{diagonal}, + Fill => $fills[$_->att('fillId')], ) } $styles->find_nodes('//cellXfs/xf'); |