#!/usr/bin/perl use strict; use warnings; use Spreadsheet::WriteExcel; use Spreadsheet::ParseExcel; my $parser = Spreadsheet::ParseExcel->new(); my $workbook_parse = $parser->Parse( 'Report.xls' ); my $worksheet_parse = $workbook_parse->Worksheet("Sheet1"); my ( $col_min, $col_max ) = $worksheet_parse->col_range(); my ( $row_min, $row_max ) = $worksheet_parse->row_range(); for my $col ( $col_min .. $col_max ) { for my $row ( $row_min .. $row_max ) { # Return the cell object at $row and $col my $cell = $worksheet_parse->get_cell( $row, $col ); next unless $cell; my $value = $cell->value(); my $format = $cell->get_format(); # Create a new Excel workbook my $workbook = Spreadsheet::WriteExcel->new( 'perl.xls' ); # Add a worksheet my $worksheet = $workbook->add_worksheet( "Health_Report" ); my $pattern = $format->{Fill}->[0]; my $front_color = $format->{Fill}->[1]; my $back_color = $format->{Fill}->[2]; my $sRGB = $parser->ColorIdxToRGB($format->{Fill}->[2]); my $backgroundcolor = $workbook->set_custom_color($back_color, $sRGB); use Color::Rgb; # Linux rgb file (I do not know if same directory in WindowsOS) my $rgb = new Color::Rgb(rgb_txt=>'/etc/X11/rgb.txt'); my $yellow_hex = $rgb->hex('yellow'); print "RGB Yellow: " . $yellow_hex . "\n"; print "RGB Excel: " . $sRGB . "\n"; print "RGB int: " . $backgroundcolor . "\n"; my %opts = (bg_color => $front_color, align => "center", pattern => $pattern, ); # Add and define a format my $format_2 = $workbook->add_format(%opts); # Write a formatted and unformatted string, row and column notation. $worksheet->write($row, $col, $value, $format_2); } } __END__ $ perl excel.pl RGB Yellow: ffff00 RGB Excel: FFFF00 RGB int: 34