diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-05-02 17:23:29 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-05-02 17:23:29 -0500 |
commit | 95cb46a9cfeff201c3c4dc9aa90a7111764f0d82 (patch) | |
tree | a918a9f0b88b652b30fca3327612edea636aa93c /lib | |
parent | 49da63477993473327d8a70469f9c6a550b0add9 (diff) | |
download | spreadsheet-template-95cb46a9cfeff201c3c4dc9aa90a7111764f0d82.tar.gz spreadsheet-template-95cb46a9cfeff201c3c4dc9aa90a7111764f0d82.zip |
start parsing out some format data
doesn't work with xlsx yet, because it puts the numerical format in the
Format cell field instead of the text format object
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Spreadsheet/Template/Generator/Parser/Excel.pm | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/Spreadsheet/Template/Generator/Parser/Excel.pm b/lib/Spreadsheet/Template/Generator/Parser/Excel.pm index 8c279cf..4326fc6 100644 --- a/lib/Spreadsheet/Template/Generator/Parser/Excel.pm +++ b/lib/Spreadsheet/Template/Generator/Parser/Excel.pm @@ -80,6 +80,7 @@ sub _parse_cell { my $contents = $cell->unformatted; my $type = $cell->type; my $formula = $cell->{Formula}; # XXX + my $format = $cell->get_format; if ($type eq 'Numeric') { $type = 'number'; @@ -94,10 +95,48 @@ sub _parse_cell { die "unknown type $type"; } + # use Data::Dump; ddx($cell); + + my $format_data = {}; + if ($format) { + my %halign = ( + 0 => 'none', + 1 => 'left', + 2 => 'center', + 3 => 'right', + 4 => 'fill', + 5 => 'justify', + 6 => 'center_across', + ); + + my %valign = ( + 0 => 'top', + 1 => 'vcenter', + 2 => 'bottom', + 3 => 'vjustify', + ); + + $format_data->{size} = $format->{Font}{Height}; + $format_data->{color} = '#' . Spreadsheet::ParseExcel->ColorIdxToRGB( + $format->{Font}{Color} + ) unless $format->{Font}{Color} == 8; # XXX + $format_data->{bg_color} = '#' . Spreadsheet::ParseExcel->ColorIdxToRGB( + $format->{Fill}[1] + ) unless $format->{Fill}[1] == 64; + $format_data->{align} = $halign{$format->{AlignH}} + unless $format->{AlignH} == 0; + $format_data->{valign} = $valign{$format->{AlignV}} + unless $format->{AlignV} == 2; + $format_data->{text_wrap} = JSON::true + if $format->{Wrap}; + # XXX num_format + } + my $data = { contents => $self->_filter_cell_contents($contents, $type), type => $type, ($formula ? (formula => $formula) : ()), + (keys %$format_data ? (format => $format_data) : ()), }; return $data; |