Handsontable 和热门公式解析器

Handsontable and hot-formula-parser

是否可以将自定义函数 ('ADD_5') include/register 放入 handsontable?

以下示例有效,从 B2 到 B4 的所有单元格值都等于 42。只有 B5 = ADD_5(37) returns #NAME?而不是 42.

我必须在哪里定义函数并将其添加到 table 的现有解析器?

<div id="example1" class="handsontable"></div>

<script data-jsfiddle="example1">
  $(document).ready(function () {
    var data1 = [
      ['Number', 'Answer'],
      [10, 42],
      [10, '=SUM(A2:A5)'],
      [10, '=A2 + A3 + A4 + A5'],
      [12, '=ADD_5(37)']
    ];
    var container1 = $('#example1');
    container1.handsontable({
      data: data1,
      minSpareRows: 1,
      colHeaders: true,
      rowHeaders: true,
      contextMenu: true,
      manualColumnResize: true,
      formulas: true
    });
    parser.setFunction('ADD_5', function(params) {
      return params[0] + 5;
    });
  });
</script>

如有任何帮助,我们将不胜感激。

According to official doc:

The Formulas plugin allows Handsontable to process formula expressions defined in the provided data. This plugin uses a formula-parser library which takes most of functions from formula.js.

您需要将公式添加到 formula.js 然后