我的Perl脚本正在生成Excel工作表。
输出
P MON #N/A XML xx ## c 2 Yes
B TUE #N/A TXT xx ## b 1 No
D SUN #N/A EXE xx ## a 1 No
我希望excel表的列以不同的颜色突出显示
我遵循了site
但我不知道使用Perl为不同的列设置不同的颜色。
答案 0 :(得分:3)
您需要将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__
这给你输出如下: