Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

datatable - 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

question from:https://stackoverflow.com/questions/65871547/two-variable-data-table-in-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...