0

我正在尝试使用 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 行

输出电子表格

4

1 回答 1

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 的索引。已报告问题。

于 2018-03-03T08:29:26.473 回答