这是公式解析器和WriteExcel中某些公式类型的已知错误。你可以使用
store_formula()
repeat_formula()
如下图所示:
use strict;
use warnings;
use Spreadsheet::WriteExcel;
my $wb = Spreadsheet::WriteExcel->new('foo.xls');
my $ws = $wb->add_worksheet;
my $formula = $ws->store_formula('=VLOOKUP(K1, A1:B10, 2, FALSE)');
# Workaround for VLOOKUP bug in WriteExcel.
@$formula = map {s/_ref2d/_ref2dV/;$_} @$formula;
for my $r (0 .. 9){
for my $c (0 .. 4){
$ws->write($r, $c, $r * 10 + $c);
}
$ws->write($r, 10, $r * 10);
$ws->repeat_formula( $r, 11, $formula, undef, qr/^K1$/, 'K' . ($r +1) );
}