简体   繁体   中英

Two-Variable Data Table in Javascript

Can I create a "Two-Variable Data Table" (aka "Two-Way Data Table") in Javascript?

In Excel, of course, this can be found in the Data, What-If Analysis, Data Table menu sequence.

I've reached out to GrapeCity, developers of SpreadJS, and am awaiting a reply.

Perhaps someone on stackoverflow has addressed this question. My searches on Google and within stackoverflow have come up empty so far.

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)

Here is the entire dataTable 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 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. Let us know if you have any questions, Best, Mackenzie

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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