[英]Set different column colors for each column in excel using Perl
My Perl script is generating an excel sheet. 我的Perl脚本正在生成excel表。
Output 产量
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
I want the excel sheet's column to be highlighted in different colours 我希望excel表的列以不同的颜色突出显示
But I am not getting any idea to set different colours for different columns using Perl . 但我不知道使用Perl为不同的列设置不同的颜色。
You need to use the set_column()
method with a format object that has the bg_color
set. 您需要将
set_column()
方法与具有bg_color
设置的格式对象bg_color
。 Here is a small working example. 这是一个小例子。
#!/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__
Which gives you output like this: 这给你输出这样的:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.