开发者

How to write formula in Excel sheet which is stored in the perl variable

开发者 https://www.devze.com 2023-02-02 12:27 出处:网络
use strict use Spreadsheet::WriteExcel; my $Workbook= Spreadsheet::WriteExcel->new(\'cw.xls\'); my $Worksheet = $Workbook->add_worksheet(\'MRD\');
use strict
use Spreadsheet::WriteExcel;
my $Workbook  = Spreadsheet::WriteExcel->new('cw.xls');
my $Worksheet = $Workbook->add_worksheet('MRD');

my $Formula= "A10开发者_JS百科+B10/2";
$Worksheet->write_formula(1,2,'='.($Formula));

exit;

Error getting:

Couldn't parse formula: =A10+B10/2;

Note : In the Formula that I am using contain across sheet data calling. When I am Pasting it in the excel sheet manually its working fine but through program I am unable to put it in the sheet.

Please if any one came across this problem or has solution let me know.


If you see the documentation of Spreadsheet::WriteExcel module, it states in the DIAGNOSTICS section that:

Couldn't parse formula ...

There are a large number of warnings which relate to badly formed formulas and functions. See the "FORMULAS AND FUNCTIONS IN EXCEL" section for suggestions on how to avoid these errors. You should also check the formula in Excel to ensure that it is valid.


There is no problem storing a formula in a variable and passing it to write_formula(). In fact your own snippet above proves that it works.

So the problem is with the formula that you are trying to write. Since you haven't posted the formula it is hard to guess what the problem might be but here are some formula debugging tips from the docs:

  1. Verify that the formula works in Excel (or Gnumeric or OpenOffice.org).
  2. Ensure that it isn't on the Caveats list shown above. (In the docs).
  3. Ensure that cell references and formula names are in uppercase.
  4. Ensure that you are using ':' as the range operator, A1:A4.
  5. Ensure that you are using ',' as the union operator, SUM(1,2,3).
  6. Ensure that the function is in the above table. (In the docs).

P.S. The leading '=' isn't required when you are using write_formula() so you can just use:

$Worksheet->write_formula(1, 2, $Formula);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号