简体   繁体   English

Javascript中的二变量数据表

[英]Two-Variable Data Table in Javascript

Can I create a "Two-Variable Data Table" (aka "Two-Way Data Table") in Javascript?我可以在 Javascript 中创建“双变量数据表”(又名“双向数据表”)吗?

In Excel, of course, this can be found in the Data, What-If Analysis, Data Table menu sequence.在 Excel 中,当然可以在 Data, What-If Analysis, Data Table 菜单序列中找到。

I've reached out to GrapeCity, developers of SpreadJS, and am awaiting a reply.我已经联系了 SpreadJS 的开发人员 GrapeCity,正在等待回复。

Perhaps someone on stackoverflow has addressed this question.也许stackoverflow上的某个人已经解决了这个问题。 My searches on Google and within stackoverflow have come up empty so far.到目前为止,我在 Google 和 stackoverflow 上的搜索都是空的。

Thanks!谢谢! Vince Lackner文斯·拉克纳

I am a member of GrapeCity's Technical Engagement team and SpreadJS's team has implemented a dataTable function that is used to create the two-way-table: function dataTable(sheet, columnRange, rowRange, colInputCell, rowInputCell, formulaCell)我是 GrapeCity 技术参与团队的成员,SpreadJS 团队已经实现了一个数据表 function,用于创建双向表:function dataTable(sheet, columnRange, rowCellRange, colInputCell, rowInputCell)

Here is the entire dataTable function:这是整个数据表function:

 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);
                }
            }
        }

Here is an example of how you would create the data table using this function:以下是如何使用此 function 创建数据表的示例:

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();
}

Note we also attached a sample showing this to your forum question on the GrapeCity website.请注意,我们还在 GrapeCity 网站上为您的论坛问题附加了一个示例。 Let us know if you have any questions, Best, Mackenzie如果您有任何问题,请告诉我们,Best,Mackenzie

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM