我目前有一个使用AngularJS / SpreadJS的解决方案,我们需要使用公式更新标题部分。当我们使用setValue更改标题中的单元格值时,everythign显示确定,但是我们需要使用setFormula显示公式,在这些情况下,公式将计算并显示在属于我的数据所在的实际工作表的行中。
//Does not work and displays in row 2 of the sheet:
sheet.setFormula(2, i, formula, GC.Spread.Sheets.SheetArea.colHeader);
//Displays value in actual header in teh correct location/header cell
sheet.setValue(2, i, 'my formula!', GC.Spread.Sheets.SheetArea.colHeader);
任何帮助将不胜感激。谢谢!
答案 0 :(得分:1)
在下面的解决方案中实现了在电子表格的列标题中实现SUM公式。可以在电子表格事件中调用此函数,如cellChanged,clipBoardPasted以实现功能。
var spread = new GC.Spread.Sheets.Workbook($("#ss").get(0), { sheetCount: 2 });
var displaySheet = spread.getSheet(0);
displaySheet.setRowCount(2, GC.Spread.Sheets.SheetArea.colHeader);
for (var i = 0; i < 10; i++) {
for (var j = 0; j < 10; j++) {
displaySheet.setValue(i, j, i + j);
}
}
$("#btnSetAutoTotal").click(function () {
setTotal(displaySheet, 0);
});
function setTotal(sheet, columnIndex) {
var formula = "SUM(R[1]C[1]:R[10]C[10]";
value = GC.Spread.Sheets.CalcEngine.evaluateFormula(sheet, 'SUM(A:A)', 0,
columnIndex, false);
sheet.setValue(0, columnIndex, value, GC.Spread.Sheets.SheetArea.colHeader);
};
答案 1 :(得分:0)
团队创建此示例以演示您需要的内容。希望这会有所帮助。
function setColumnHeaderFunction() {
this.name = "SetColumnHeader";
this.maxArgs = 3;
this.minArgs = 3;
}
setColumnHeaderFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
setColumnHeaderFunction.prototype.description = function () {
return {
name:"SetColumnHeader",
description: "The function will apply the calc result on specified column",
parameters: [{
name: "result",
description: "The value which will be setted on column"
}, {
name: "rowIndex",
description: "The row index"
}, {
name: "colIndex",
description: "The column index"
}]
}
}
setColumnHeaderFunction.prototype.evaluate = function () {
var value = arguments[0], rowIndex = arguments[1], colIndex = arguments[2];
var spread = GC.Spread.Sheets.findControl("ss");
var sheet = spread.getSheet(0);
sheet.setValue(rowIndex, colIndex, value, GC.Spread.Sheets.SheetArea.colHeader);
}
$(document).ready(function () {
var spread = new GC.Spread.Sheets.Workbook($("#ss").get(0), {sheetCount: 2});
spread.addCustomFunction(new setColumnHeaderFunction());
var displaySheet = spread.getSheet(0);
displaySheet.setDataSource(getSource(100));
displaySheet.setRowCount(3, GC.Spread.Sheets.SheetArea.colHeader);
displaySheet.setValue(0,0,"Count:",GC.Spread.Sheets.SheetArea.colHeader);
displaySheet.setValue(0,3,"Sum:",GC.Spread.Sheets.SheetArea.colHeader);
displaySheet.setValue(0,4,"Average:",GC.Spread.Sheets.SheetArea.colHeader);
displaySheet.setValue(0,5,"Sum:",GC.Spread.Sheets.SheetArea.colHeader);
var calcSheet = spread.getSheet(1);
calcSheet.visible(false);
calcSheet.setFormula(0, 1, "SetColumnHeader(SUM(Sheet1!D:D),1,3)");
calcSheet.setFormula(0, 2, "SetColumnHeader(AVERAGE(Sheet1!E:E),1,4)");
calcSheet.setFormula(0, 3, "SetColumnHeader(SUM(Sheet1!F:F),1,5)");
calcSheet.setFormula(0, 4, "SetColumnHeader(COUNT(Sheet1!A:A),1,0)");
});
function getSource(count) {
var dataList = [];
var _lines = ["Computers", "Washers", "Stoves"];
var _colors = ["Red", "Green", "Blue", "White"];
for (var i = 0; i < count; i++) {
dataList.push({
id: i,
line: _lines[parseInt(Math.random() * 3)],
color: _colors[parseInt(Math.random() * 4)],
price: parseInt(Math.random() * 501 + 500),
cost: parseInt(Math.random() * 601),
weight: parseInt(Math.random() * 101),
})
}
return dataList;
}
&#13;