您需要将该set_column()
方法与具有该bg_color
集合的格式对象一起使用。这是一个小的工作示例。
#!/usr/bin/perl
use strict;
use warnings;
use Spreadsheet::WriteExcel;
my $workbook = Spreadsheet::WriteExcel->new( 'columns.xls' );
my $worksheet = $workbook->add_worksheet();
# Add some formats with background colors.
my $format1 = $workbook->add_format( bg_color => 'yellow' );
my $format2 = $workbook->add_format( bg_color => 0x32 );
# Format column A with a background color of yellow.
$worksheet->set_column('A:A', undef, $format1);
# Format column c with a new width and light green.
$worksheet->set_column('C:C', 30, $format2);
# Add some data to the worksheet.
my $headings = [ 'Column 1', 'Column 2', 'Column 3' ];
my $data = [
[ 2, 3, 4, 5, 6, 7 ],
[ 1, 4, 5, 2, 1, 5 ],
[ 3, 6, 7, 5, 4, 3 ],
];
$worksheet->write( 'A1', $headings );
$worksheet->write( 'A2', $data );
__END__
这会给你这样的输出: