Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get both value and formula #1664

Closed
shihlun1208 opened this issue Dec 6, 2023 · 1 comment
Closed

Get both value and formula #1664

shihlun1208 opened this issue Dec 6, 2023 · 1 comment

Comments

@shihlun1208
Copy link

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?

@shihlun1208
Copy link
Author

shihlun1208 commented Dec 7, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant