【问题标题】:Handsontable - Calculating values that include commasHandsontable - 计算包含逗号的值
【发布时间】:2017-05-13 06:32:05
【问题描述】:

我有一个使用handsontable 的网页。在此页面中,我尝试以编程方式将一些数据放入电子表格并执行一些公式。在值包含逗号之前,我的公式可以正常工作。比如在this JSFiddle,我有如下代码:

var hot =  null;

initHot();
loadFormulas();
loadData();

function initHot() {
  var container = document.getElementById('example');

  var hCols = [ 'A', 'B', 'C', 'D', 'E' ];
  var hRows = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ];
  var sdata = [
    [ 0, 0, 0, 0, 0, 0 ],
    [ 0, 0, 0, 0, 0, 0 ],
    [ 0, 0, 0, 0, 0, 0 ],
    [ 0, 0, 0, 0, 0, 0 ],
    [ 0, 0, 0, 0, 0, 0 ],
    [ 0, 0, 0, 0, 0, 0 ],
    [ 0, 0, 0, 0, 0, 0 ],
    [ 0, 0, 0, 0, 0, 0 ],
    [ 0, 0, 0, 0, 0, 0 ],
    [ 0, 0, 0, 0, 0, 0 ]  
  ];

  hot = new Handsontable(container, {
    startRows: hRows.length,
    rowHeaders: hRows,
    startCols: hCols.length,
    colHeaders: hCols,
    data: sdata,
    formulas: true,
    height: 300
  });
}

function loadFormulas() {
  // In my app, this happens async, but I'm just plugging it in here to demo it.
  hot.setDataAtCell(2, 0, '=A1-A2');
  hot.setDataAtCell(9, 0, '=SUM(A3:A9)');
}

function loadData() {
  // In my app, this happens at runtime, but I'm just plugging it in here to demo it.
  hot.setDataAtCell(0, 0, '1000');
  hot.setDataAtCell(1, 0, '3000');

  hot.setDataAtCell(3, 0, '5000');
  hot.setDataAtCell(4, 0, '6500');
  hot.setDataAtCell(5, 0, '7000');
  hot.setDataAtCell(6, 0, '8000');
  hot.setDataAtCell(7, 0, '9000');
  hot.setDataAtCell(8, 0, '10,000');
}

单元格 A10 的结果应该是 43500。但是,由于单元格 A9 中的逗号,它计算不正确。当出现逗号时,Handsontable 将单元格中的值视为零。如果将 10,000 更改为 10000,则计算正确。如何在值中支持逗号以使公式仍然正确执行?

【问题讨论】:

  • 我也有同样的问题。你解决了这个问题吗?

标签: javascript handsontable


【解决方案1】:

由于 localmachine 的区域设置,您的电子表格可能计算不正确。尝试改变“。”使用 "," 或更改本地计算机上的日期 - 时间 - 数字格式。

【讨论】:

猜你喜欢
  • 2018-06-13
  • 1970-01-01
  • 2023-04-03
  • 2011-08-02
  • 2020-09-30
  • 1970-01-01
  • 2021-09-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多