jspreadsheet/ce

Get both value and formula

shihlun1208 opened this issue · 1 comments

I have tried to set copyCompatibility:true, to get the value executed by formula.
But what I probably need is formula as well.

I need to get data and send it to my python backend, and store all the table data.
But if I send with formula, I need to convert the formula myself in the backend,
if I send with value, I cannot render with formula data in frontend next time.
So I'm thinking that maybe I need both formula data and value data.
Is it possible to get both types of data?

I think I found the way to get the formula data, if there is another easy way to do this, please let me know, thanks a lot!

let myTable = jspreadsheet(document.getElementById('spreadsheet'), {
    data: data2,
    copyCompatibility:true,
    search:true,
});

To get formula data:
Call getFormulaData()

function getFormulaData(highlighted) {
    // Control vars
    var dataset = [];
    var px = 0;
    var py = 0;

    // Data type
    // var dataType = dataOnly == true || obj.options.copyCompatibility == false ? true : false;
    var dataType = true;

    // Column and row length
    var x = myTable.options.columns.length
    var y = myTable.options.data.length

    // Go through the columns to get the data
    for (var j = 0; j < y; j++) {
        px = 0;
        for (var i = 0; i < x; i++) {
            // Cell selected or fullset
            if (! highlighted || myTable.records[j][i].classList.contains('highlight')) {
                // Get value
                if (! dataset[py]) {
                    dataset[py] = [];
                }
                if (! dataType) {
                    dataset[py][px] = myTable.records[j][i].innerHTML;
                } else {
                    dataset[py][px] = myTable.options.data[j][i];
                }
                px++;
            }
        }
        if (px > 0) {
            py++;
        }
   }

   return dataset;
}

To get value Data:
Just call myTable.getData()