1

Using Perl Write Excel XLS, I am reading from File 1 and writing to File 2. While my code successfully writes the same data from File 1 and File 2, however the File 2 does not maintain the same color format as File 1 (File 1 Excel displays a blue and white format for every other row).

Is there an option in Perl Excel Parse/Write to maintain the same color code? I've researched in CPAN and this site but I am unable to discover any options to be applied in the Perl script.

My Code:

##! /usr/bin/perl
use v5.10.0;
use warnings;


use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::SaveParser;
use Spreadsheet::WriteExcel;


my $parser = Spreadsheet::ParseExcel::SaveParser->new();
my $workbook_R = $parser->parse('C:\Perl\databases\File1.xls');

my $workbook_W = Spreadsheet::WriteExcel->new('C:\Perl\databases\File2.xls');
my $worksheet_W = $workbook_W->add_worksheet();

for my $worksheet_R ($workbook_R->worksheets()) {

my ($row_min, $row_max ) = $worksheet_R->row_range();
my ($col_min, $col_max ) = $worksheet_R->col_range(); 


  for my $row ($row_min .. $row_max ) {
  for my $col ($col_min .. $col_max ) {

  my $value = $worksheet_R->get_cell($row, $col)->value;
  $worksheet_W->write($row, $col, $value);
   }
  }
 }
Minimalist
  • 963
  • 12
  • 34
  • I think that you don't need the `WriteExcel` module for what you are doing, but only the `Spreadsheet::ParseExcel::SaveParser`. See for instance [this post](https://stackoverflow.com/a/3217450/4653379). That may preserve colors. If not, there is a range of options involving colors so should be able to read off what they are and then specify them again. – zdim Sep 09 '18 at 05:09
  • @zdim thanks for the reference. I'll try a few of the options and see if it preserves the color. – Minimalist Sep 09 '18 at 05:12
  • OK. Note that at the same page there is another answer where they indeed use the combo you have. But then, it's different modules; i am not sure I'd bet that the writer will pick up _everything_ from the reader. – zdim Sep 09 '18 at 05:14

0 Answers0