From 95cb46a9cfeff201c3c4dc9aa90a7111764f0d82 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 2 May 2013 17:23:29 -0500 Subject: 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 --- lib/Spreadsheet/Template/Generator/Parser/Excel.pm | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) 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; -- cgit v1.2.3-54-g00ecf