我可以创建一个"双变量数据表"吗?(又名"双向数据表")在JavaScript?
当然,在Excel中,这可以在数据、假设分析、数据表菜单序列中找到。
SpreadJS的团队已经实现了一个dataTable函数,用于创建双向表:function dataTable(sheet, columnRange, rowRange, colInputCell, rowInputCell, formulaCell)
下面是整个dataTable函数:
function dataTable(sheet, columnRange, rowRange, colInputCell, rowInputCell, formulaCell) {
var colRg = GC.Spread.Sheets.CalcEngine.formulaToRange(sheet, columnRange);
var rowRg = GC.Spread.Sheets.CalcEngine.formulaToRange(sheet, rowRange);
var colCell = GC.Spread.Sheets.CalcEngine.formulaToRange(sheet, colInputCell);
var rowCell = GC.Spread.Sheets.CalcEngine.formulaToRange(sheet, rowInputCell);
var fCell = GC.Spread.Sheets.CalcEngine.formulaToRange(sheet, formulaCell);
for (var i=colRg.col; i<colRg.col + colRg.colCount; i++) {
sheet.setValue(colCell.row, colCell.col, sheet.getValue(colRg.row, i));
for (j=rowRg.row; j<rowRg.row + rowRg.rowCount; j++) {
sheet.setValue(rowCell.row, rowCell.col, sheet.getValue(j, rowRg.col));
var v = sheet.getValue(fCell.row, fCell.col);
sheet.setValue(j, i, v);
}
}
}
下面是如何使用这个函数创建数据表的示例:
function createDataTable() {
var ss = GC.Spread.Sheets.findControl('ss');
var sheet = ss.getActiveSheet();
ss.suspendPaint();
dataTable(sheet, 'G1:K1', 'F2:F6', 'B1', 'B2', 'B4');
ss.resumePaint();
}
我是GrapeCity技术参与团队的成员。