我正在尝试使用perl模块Excel :: Writer :: XLSX构建一个包含轮廓行的电子表格。我需要行轮廓符号显示在大纲级别栏上方。当我运行下面的脚本时,正确生成了轮廓符号和水平条,但向下移动了一行。
use strict;
use Excel::Writer::XLSX;
my $visible = 1;
my $symbols_below = 0;
my $symbols_right = 0;
my $auto_style = 0;
my $output_rpt = 'report.xlsx';
my $color1 = "#CBBEA0";
my $color2 = "#DDD7C5";
my $workbook = Excel::Writer::XLSX->new( $output_rpt );
my $worksheet1 = $workbook->add_worksheet( 'report' );
$worksheet1->outline_settings($visible, $symbols_below, $symbols_right, $auto_style);
my $format1 = $workbook->add_format( bold => 1, bg_color => $color1, align => 'center' );
my $format2 = $workbook->add_format( bold => 1, bg_color => $color1, align => 'left' );
my $format3 = $workbook->add_format( bold => 1, bg_color => $color2, align =>'left' );
my $format4 = $workbook->add_format( align => 'center' );
my @last = qw( Smith Jones Panglossian );
my @first = qw( Algonquin Mephibosheth Noah );
my @age = (24, 42, 962);
my @hidden = (0, 0, 0);
my @level = (0, 1, 1);
my @collapsed = (1, 0, 0);
for my $idx (0..2) {
my $row = $idx+1;
$worksheet1->set_row( $row, undef, undef, $hidden[$idx], $level[$idx],
$collapsed[$idx] );
$worksheet1->write( 'A' . $row, $first[$idx], $format2);
$worksheet1->write( 'B' . $row, $last[$idx], $format3);
$worksheet1->write( 'C' . $row, $age[$idx], $format4);
}
$workbook->close();
输出电子表格如下图所示。请注意,轮廓条偏移1行
答案 0 :(得分:1)
如果查看Excel::Writer::XLSX
方法的set_row
文档,您会看到:
$worksheet->set_row( 0, 20 ); # Row 1 height set to 20
这意味着索引是从0开始的,但是你给它$idx+1
。将该行更改为以下内容,它应该按预期工作(当我在我的测试结果时,它对我有用):
$worksheet1->set_row( $idx, undef, undef, $hidden[$idx], $level[$idx], $collapsed[$idx] );
# ^^^
(文档中似乎有一个错误,其中一个示例显示了一个基于1的索引。Issue reported.)