http://www.perlmonks.org?node_id=853217

irDanR has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to combine a single worksheet from each of a dozen different workbooks into a single new workbook. I can do this perfectly with ParseExcel and WriteExcel. However I need to retain the formatting of the original sheets.

Enter ParseExcel::SaveParser.

use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::SaveParser; use Spreadsheet::WriteExcel; my $parser = Spreadsheet::ParseExcel::SaveParser->new(); my $template = $parser->Parse('test.xls'); $template->SaveAs('test.xls');
(Basically copied from the synopsis.) Running it on an example workbook gives me almost perfect results. The cell size, border, font, etc. are all correct. However, the font color as well as background color change. As in, black font turns into impossible to read light blue or pink.

I notice that once the worksheet has been run through SaveParser, the colors stay the same in subsequent passes. This got some gears turning and I found that it only happens to an xls once after downloading from google docs.

Just to be painfully clear:
1) Downloaded test.xls from google docs.
2) Run through SaveParser with the above code. (changes the colors)
3) Run through same code, color stays the same.
4) Upload to google docs then download from google docs.
5) Run through code again, colors change.

My situation requires that I download the docs from google and then combine into a new doc and then upload back to google weekly. Does anyone have any experience with this or have any suggestions for making the colors stay the same? I foresee this requiring me to become much more familiar with the google doc API...

Update: An interesting find, using:
my $parser = Spreadsheet::ParseExcel::SaveParser->new(); my $template = $parser->Parse('test.xls'); my $line = 0; my $file = "color.txt"; tie my @array, 'Tie::File', $file or die "Cannot open $file: $!"; for my $worksheet ($template->worksheets() ) { my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); for my $row ( $row_min .. $row_max ) { for my $col ( $col_min .. $col_max ) { $line++; my $cell = $worksheet->get_cell( $row, $col ); next unless $cell; my $format = $cell->get_format(); my $font = $format->{Font}; my $color = $font->{Color}; $array[$line] .= "\t $color"; } } } untie @array;
to get a number for the color - when I output the number to a file and then compare it before the color change and after the change, gives me the same number.