gpt4 book ai didi

javascript - 如何发送带有公式字段的手写表

转载 作者:行者123 更新时间:2023-11-29 18:07:16 29 4
gpt4 key购买 nike

我已经创建了带有公式字段的 handsontable。当我保存表时,我在 c# 数据表中得到了公式而不是公式结果。听到的是我将表格发送到 C# web 方法的代码:

var workTypeData = $.parseJSON(data.d[1]);
var container = document.getElementById('example');
hot = new Handsontable(container, {
data: workTypeData,
rowHeaders: true,
contextMenu: false,
colHeaders: ['RoomDescriptionID', 'RoomDescriptionName', 'Area', 'Perimeter', 'Height'],
columns: [
{ data: 'RoomDescriptionID' },
{ data: 'RoomDescriptionName' },
{ data: 'Area' },
{ data: 'Perimeter' },
{ data: 'Height' }
],
formulas: true,
manualColumnResize: true
});

var mydata = JSON.stringify(hot.getData());
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "FormulaBuilder.aspx/OnSave",
data: "{ 'data' : '" + mydata + "' }",
success: function (data) {
if (data.d[0].length > 0) {
alert("error in code");
} else {

}
},
error: function (jqXhr, exception) {
alert("error in ajax");
}
});

下面是我的 C# web 方法:

var dt = JsonConvert.DeserializeObject<DataTable>(data);

我在 json formate 中得到数据,如下所示:

[{"RoomDescriptionID":1,"RoomDescriptionName":"Vestibule + Living + Dining","Area":"=SUM(D1:E1)","Perimeter":"=$E1/0.5","Height":0},{"RoomDescriptionID":2,"RoomDescriptionName":"Kitchen","Area":"=SUM(D2:E2)","Perimeter":"=$E2/0.5","Height":0},{"RoomDescriptionID":3,"RoomDescriptionName":"Area below Kitchen Platform","Area":"=SUM(D3:E3)","Perimeter":"=$E3/0.5","Height":0},{"RoomDescriptionID":4,"RoomDescriptionName":"Bed Room 1","Area":"=SUM(D4:E4)","Perimeter":"=$E4/0.5","Height":0},{"RoomDescriptionID":5,"RoomDescriptionName":"BR1 Toilet + Dress","Area":"=SUM(D5:E5)","Perimeter":"=$E5/0.5","Height":0},{"RoomDescriptionID":6,"RoomDescriptionName":"Bed Room 2","Area":"=SUM(D6:E6)","Perimeter":"=$E6/0.5","Height":0},{"RoomDescriptionID":7,"RoomDescriptionName":"BR2 Toilet + Dress","Area":"=SUM(D7:E7)","Perimeter":"=$E7/0.5","Height":0},{"RoomDescriptionID":8,"RoomDescriptionName":"Bed Room 3","Area":"=SUM(D8:E8)","Perimeter":"=$E8/0.5","Height":0},{"RoomDescriptionID":9,"RoomDescriptionName":"BR3 Toilet + Dress","Area":"=SUM(D9:E9)","Perimeter":"=$E9/0.5","Height":0}]

在 Area 中,它返回公式而不是结果

谢谢。

最佳答案

我有同样的问题,但在 this question 的帮助下解决了它.

首先,您可以使用 hot.plugin.helper.cellValue('CELL REF') 获取实际值,但在使用 getData() 时,您会查看整个集合。为了解决这个问题,我基本上遍历了数组,用值替换了任何公式单元格(我只需要直到“K”的列):

var aCols = ['A','B','C','D','E','F','G','H','I','J','K'];                   
var mydata = hot.getData();

for (i = 0; i < mydata.length; i++){
for(j = 0; j < mydata[i].length; j++){
if(mydata[i][j].toString().indexOf('=') > -1){
mydata[i][j] = hot.plugin.helper.cellValue (aCols[j] + (i+1));
}
}
}

关于javascript - 如何发送带有公式字段的手写表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30317791/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com