[英]Spreadsheet::WriteExcel while writing the formula, its considered as string
I am writing the VLOOKUP formula to an excel. 我正在将VLOOKUP公式编写为Excel。 i tried directly writing the formula using write_formula.
我尝试使用write_formula直接编写公式。 I used to get #VALUE!
我曾经获得#VALUE! error in excel when i hit ctrl+shift+enter in excel it works fine.
当我在excel中按ctrl + shift + enter时,excel中出现错误,它工作正常。 Also tried with store_formula & repeat formula same error.
还尝试了与store_formula和重复公式相同的错误。
Looks like the formula is considered as string. 看起来该公式被视为字符串。 Is there a way to overcome this problem?
有办法解决这个问题吗? Please help!
请帮忙!
my $i = 0;
foreach (@col){
my $op_mode_lookup = $worksheet1->store_formula("=VLOOKUP(B16,DB Sheet!A2:D5,".(${i}+1).",FALSE)");
.
.
.
$worksheet1->repeat_formula('B'.$row_count, $op_mode_lookup, undef);
$i++;
}
I tried replacing the "store_formula("=VLOOKUP(B16,DB Sheet!A2:D5,".(${i}+1).",FALSE)");" 我尝试替换“ store_formula(“ = VLOOKUP(B16,DB Sheet!A2:D5,”。($ {i} +1)。“,FALSE)”);“ with below still the same error.
与下面仍然是相同的错误。
store_formula('=VLOOKUP(B16,DB Sheet!A2:D5,'.(${i}+1).',FALSE)'); store_formula('= VLOOKUP(B16,DB Sheet!A2:D5,'。($ {i} +1)。',FALSE)'); store_formula('=VLOOKUP(B16,DB Sheet!A2:D5,2,FALSE)');
store_formula('= VLOOKUP(B16,DB Sheet!A2:D5,2,FALSE)');
Is there an alternative perl module for Spreadsheet::WriteExcel, which would overcome this issue? Spreadsheet :: WriteExcel是否有替代的perl模块,可以克服此问题?
There are several issues here: 这里有几个问题:
DB Sheet
contains a space so Excel requires that it is enclosed in single quotes when used in formulas, like this: "=VLOOKUP(B16,'DB Sheet'!A2:D5,1,FALSE)"
. DB Sheet
包含一个空格,因此Excel在公式中使用时要求将其用单引号引起来,例如: "=VLOOKUP(B16,'DB Sheet'!A2:D5,1,FALSE)"
。 store_formula()
repeatedly in a loop. store_formula()
。 This is inefficient and incorrect. store_formula()
is that the expensive formula parse is only done once and that the pre-parsed formula can then be reused via repeat_formula()
. store_formula()
的要点是,昂贵的公式解析仅进行一次,然后可以通过repeat_formula()
重用预先解析的公式。 The is explained at some length in the documentation and shown in numerous examples . VLOOKUP
formulas when used from Spreadsheet::WriteExcel. VLOOKUP
公式。 A workaround is shown in the code below. So, fixing these issues would give something like this: 因此,解决这些问题将得到以下信息:
#!/usr/bin/perl -w
use strict;
use Spreadsheet::WriteExcel;
my $workbook = Spreadsheet::WriteExcel->new( 'demo.xls' );
my $worksheet1 = $workbook->add_worksheet();
my $worksheet2 = $workbook->add_worksheet('DB Sheet');
$worksheet1->write( 'B16', 1 );
for my $row ( 0 .. 7 ) {
$worksheet2->write( $row, 0, $row );
}
my $op_mode_lookup = $worksheet1->store_formula(
"=VLOOKUP(B16,'DB Sheet'!A2:D5,1,FALSE)");
# Workaround for VLOOKUP bug in WriteExcel.
@$op_mode_lookup = map {s/_ref2d/_ref2dV/;$_} @$op_mode_lookup;
my @col = (0, 1, 2, 3);
my $row_count = 1;
foreach ( @col ){
$worksheet1->repeat_formula('B' . $row_count, $op_mode_lookup, undef);
$row_count++;
}
__END__
However , I would advise avoiding all of this store_formula()
code and workaround and just use Excel::Writer::XLSX instead. 但是 ,我建议避免使用所有此类
store_formula()
代码和变通办法,而应改用Excel :: Writer :: XLSX 。
It is API compatible with Spreadsheet::WriteExcel and has faster and non-buggy formula support. 它与Spreadsheet :: WriteExcel兼容,并且具有更快,更轻松的公式支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.