New Options missing in fromJSON deserializationOptions

Posted by: m.holland-moritz on 6 February 2023, 8:30 am EST

    • Post Options:
    • Link

    Posted 6 February 2023, 8:30 am EST

    Hello everyone,

    I recently upgraded from version 14.2.0 to version 16.0.2. This has added new options to the file open menu.

    → Lazy Load

    → Include unused styles

    → Calculate on demand

    → Dynamic References

    Since I overwrote the Open method with my own to have more access to the selected file, I ended up using a call with its fromJSON method. I noticed that the new options do not appear in the deserializationOptions.

    Now I am wondering how to implement them.

    My overwritten method for excel files:

    GC.Spread.Sheets.Designer.FileMenuHandler.importExcel_online = function () {
        let incrementalLoading = isOptionChecked("Incremental Loading");
        let doNotImportStyle = isOptionChecked("Do not import style");
        let doNotImportFormula = isOptionChecked("Do not import formula");
        let doNotAutoCalculate = isOptionChecked("Do not auto-calculate formulas after importing");
        let frozenColumns = isOptionChecked("Import frozen rows as column headers");
        let frozenRows = isOptionChecked("Import frozen columns as row headers");
        let password = findInputValue("Password");
        let input = document.createElement('input');
        input.type = 'file';
        input.onchange = _ => {
    
            let files = Array.from(input.files);
            console.log(files[0].name);
            /*import the excel file*/
            var excelIo = new GC.Spread.Excel.IO();
            excelIo.open(
                files[0],
                function (json) {
                    let designer = new GC.Spread.Sheets.Designer.Designer("designer-container");
                    let spread = designer.getWorkbook();
                    var workbookObj = json;
                    if (incrementalLoading) {
                        spread.fromJSON(workbookObj, {
                            ignoreStyle: doNotImportStyle,
                            ignoreFormula: doNotImportFormula,
                            frozenColumnsAsRowHeaders: frozenRows,
                            frozenRowsAsColumnHeaders: frozenColumns,
                            doNotRecalculateAfterLoad: doNotAutoCalculate,
                            incrementalLoading: {
                                loading: function (progress, args) {
                                    console.log("current loading sheet", args.sheet && args.sheet.name());
                                },
                                loaded: function () {
                                    console.log("Loaded");
                                }
                            }
                        });
                    } else {
                        spread.fromJSON(workbookObj, {
                            ignoreStyle: doNotImportStyle,
                            ignoreFormula: doNotImportFormula,
                            frozenColumnsAsRowHeaders: frozenRows,
                            frozenRowsAsColumnHeaders: frozenColumns,
                            doNotRecalculateAfterLoad: doNotAutoCalculate,
                        });
                    }
                    designer.setData("FileMenu_show", false);
                },
                function (e) {
                    /* process error*/
                    alert(e.errorMessage);
                    if (e.errorCode === 2/*noPassword*/ || e.errorCode === 3 /*invalidPassword*/) {
                        console.log("password error");
                    }
                }, { password: password }
            );
        }
        input.click();
    }

    Thanks in advance

    Best regards

    Maik

  • Posted 7 February 2023, 11:19 pm EST

    Hello Maik,

    Thank you for your previous message and the code snippet you shared. I appreciate your help in this matter. I am currently working on creating a sample using the latest version of SpreadJS Designer V16, and I will update you with my progress soon.

    Best regards,

    Ankit

  • Posted 8 February 2023, 11:51 pm EST

    Hi Maik,

    Thank you for your patience. With SpreadJS V16, the “spread.import()” method imports the object state from the excel or ssJson or csv file or javascript file.

    You could simply overrride the import method and you will get the file as the first argument in the import method. You could refer to the following code snippet and the sample:

    // Override the import method
    let oldImportFn = GC.Spread.Sheets.Workbook.prototype.import;
    GC.Spread.Sheets.Workbook.prototype.import = function (file, successCallBack, errorCallBack, importOptions) {
        let result = oldImportFn.apply(this, [file, successCallBack, errorCallBack, importOptions]);
        console.log(file);
        console.log("File Name: " + file.name);
        return result;
    }

    Sample: https://jscodemine.grapecity.com/share/pb5w_HJXYUGWJm7VNrBGVg/?defaultOpen={"OpenedFileName"%3A["%2Findex.html"%2C"%2Fpackage.json"%2C"%2Fsrc%2Fapp.js"]%2C"ActiveFile"%3A"%2Fsrc%2Fapp.js"}

    References:

    import method: https://www.grapecity.com/spreadjs/api/classes/GC.Spread.Sheets.Workbook#import

    SpreadJS File Format Demo: https://www.grapecity.com/spreadjs/demos/features/spreadjs-file-format/overview/purejs

    Regards,

    Ankit

  • Posted 9 February 2023, 2:52 am EST

    Hi Ankit,

    thanks for the help, this should work.

    I just didn’t realize its a different function now.

    With that i am able to resolve my problem. Thanks for the fast help.

    Best Regards,

    Maik

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels