【发布时间】: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,则计算正确。如何在值中支持逗号以使公式仍然正确执行?
【问题讨论】:
-
我也有同样的问题。你解决了这个问题吗?