zkyg/spreadsheet-formula-laravel

使用 PHP(通过 PHPSpreadsheet)解析和计算简单的 Ms Excel 公式,适用于 Laravel

v1.0.3 2021-08-06 05:51 UTC

This package is auto-updated.

Last update: 2024-09-06 15:04:04 UTC


README

库,用于在 Laravel 项目中解析和执行简单的电子表格公式。基本上是使用 PhpSpreadsheet 来模拟和获取公式结果。

  • 安装
composer require zkyg/spreadsheet-formula-laravel
  • 如何使用
$formula = "=IF( [[value1]] < 5, \"ok\", [[value1]] + [[value2]] )";
$values = [
    'value1' => 7,
    'value2' => 3
];
$res = \zkyg\SpreadsheetFormulaLaravel\SpreadsheetFormulaParser::getInstance()->calculate(
    $formula,
    $values
);
// $res = 10
  • 规则
- Parameter count have to be equals in both formula & value list.
- Value index name is alphanumeric and cannot begin with number.
- Function segment separated with "," not ";"