$format3 = $workbook->add_format(); # Add a format
$format3->set_num_format('m/d/yyyy');
$workbook->set_column('E:E', 10, $format3);
$workbook->set_column('L:L', 10, $format3);
$workbook->set_column('S:S', 10, $format3);
$format16 = $workbook->add_format(); # Add a format
$format16->set_bg_color('light blue');
I want to be able to combine all of this into one format of having
columns E, L, and S to have the date format, and the entire row to
have a background color of light blue.
Any help is greatly appreciated.
Thanks,
Keith
Thanks for the response.
> > Keith- Hide quoted text -
>
> - Show quoted text -
Combining formats in Spreadsheet::WriteExcel takes a little bit of
work. As Wardy pointed out above each unique format required a unique
format object.
The best way to achieve this is to store the properties that you wish
to set in hashes and then pass these hashes to the add_format()
constructor. An example of this is shown in the chess.pl program in
the distro:
http://search.cpan.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.18/
examples/chess.pl
There are a few things to remember:
1. A cell format over-rides a row format overrides a column format.
2. You must call set_row and set_column before calling write();
Here is another small example. Note that the row and column format
properties are combined for a cell format:
#!/usr/bin/perl -w
use strict;
use Spreadsheet::WriteExcel;
my $workbook = Spreadsheet::WriteExcel->new('reload.xls');
my $worksheet = $workbook->add_worksheet();
my %col_formats = (num_format => 'm/d/yyyy', fg_color => 'red');
my %row_formats = (italic => 1, fg_color =>
'yellow');
my $col_format = $workbook->add_format(%col_formats);
my $row_format = $workbook->add_format(%row_formats);
my $cell_format = $workbook->add_format(%col_formats,
%row_formats);
my $data = [
['Foo', 1, 39115, 1],
['Bar', 12, 39116, 2],
['Ace', 31, 39117, 3],
['Moo', 33, 39118, 4],
['Cow', 34, 39119, 5],
['Apt', 8, 39120, 6],
['Rag', 1, 39121, 7],
];
$worksheet->set_column('C:C', 20, $col_format);
$worksheet->set_row(4, undef, $row_format);
$worksheet->write_col('A1', $data);
# Overwrite Cell C5
$worksheet->write('C5', 39119, $cell_format);
__END__
John.
--