summaryrefslogtreecommitdiffstats
path: root/lib/Spreadsheet/ParseXLSX.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-05-13 13:04:52 -0500
committerJesse Luehrs <doy@tozt.net>2013-05-13 13:04:52 -0500
commit0e5acf06cdf33c97f2c77488572ec4edfd8246a0 (patch)
tree623ece4edef2f42d347731983acb04e166a20d44 /lib/Spreadsheet/ParseXLSX.pm
parentaa2752584ff0bdf1257a310272a2522049e224a6 (diff)
downloadspreadsheet-parsexlsx-0e5acf06cdf33c97f2c77488572ec4edfd8246a0.tar.gz
spreadsheet-parsexlsx-0e5acf06cdf33c97f2c77488572ec4edfd8246a0.zip
start extracting some colors
Diffstat (limited to 'lib/Spreadsheet/ParseXLSX.pm')
-rw-r--r--lib/Spreadsheet/ParseXLSX.pm54
1 files changed, 51 insertions, 3 deletions
diff --git a/lib/Spreadsheet/ParseXLSX.pm b/lib/Spreadsheet/ParseXLSX.pm
index 3e1ebae..8985657 100644
--- a/lib/Spreadsheet/ParseXLSX.pm
+++ b/lib/Spreadsheet/ParseXLSX.pm
@@ -49,7 +49,11 @@ sub _parse_workbook {
$workbook->{FmtClass} = Spreadsheet::ParseExcel::FmtDefault->new; # XXX
- my $styles = $self->_parse_styles($files->{styles});
+ my $themes = $self->_parse_themes($files->{themes}[0]); # XXX
+
+ $workbook->{Color} = $themes->{Color};
+
+ my $styles = $self->_parse_styles($workbook, $files->{styles});
$workbook->{Format} = $styles->{Format};
$workbook->{FormatStr} = $styles->{FormatStr};
@@ -141,9 +145,27 @@ sub _parse_shared_strings {
];
}
+sub _parse_themes {
+ my $self = shift;
+ my ($themes) = @_;
+
+ my @color = map {
+ $_->name eq 'a:sysClr' ? $_->att('lastClr') : $_->att('val')
+ } $themes->find_nodes('//a:clrScheme/*/*');
+
+ # this shouldn't be necessary, but the documentation is wrong here
+ # see http://stackoverflow.com/questions/2760976/theme-confusion-in-spreadsheetml
+ ($color[0], $color[1]) = ($color[1], $color[0]);
+ ($color[2], $color[3]) = ($color[3], $color[2]);
+
+ return {
+ Color => \@color,
+ }
+}
+
sub _parse_styles {
my $self = shift;
- my ($styles) = @_;
+ my ($workbook, $styles) = @_;
my %format_str = map {
$_->att('numFmtId') => $_->att('formatCode')
@@ -154,7 +176,12 @@ sub _parse_styles {
Spreadsheet::ParseExcel::Font->new(
Height => 0+$_->first_child('sz')->att('val'),
# Attr => $iAttr,
- # Color => $iCIdx,
+ # XXX not sure if there's a better way to keep the indexing stuff
+ # intact rather than just going straight to #xxxxxx
+ Color => $self->_color(
+ $workbook->{Color},
+ $_->first_child('color')
+ ),
# Super => $iSuper,
# UnderlineStyle => $iUnderline,
Name => $_->first_child('name')->att('val'),
@@ -300,4 +327,25 @@ sub _cell_to_row_col {
return ($row, $col);
}
+sub _color {
+ my $self = shift;
+ my ($colors, $color_node) = @_;
+
+ my $color; # XXX
+ if ($color_node) {
+ $color = '#000000' # XXX
+ if $color_node->att('auto');
+ $color = '#' . Spreadsheet::ParseExcel->ColorIdxToRGB( # XXX
+ $color_node->att('indexed')
+ ) if defined $color_node->att('indexed');
+ $color = '#' . substr($color_node->att('rgb'), 2, 6)
+ if defined $color_node->att('rgb');
+ $color = '#' . $colors->[$color_node->att('theme')]
+ if defined $color_node->att('theme');
+ # XXX tint?
+ }
+
+ return $color;
+}
+
1;