toJSON throws .split is not a function error

Posted by: m.holland-moritz on 1 December 2021, 1:17 am EST

  • Posted 1 December 2021, 1:17 am EST

    Hello Team,

    I am facing another issue in SpreadJS.

    With some excel files the toJSON function is throwing an error somehow.

    I am attaching a zip with a picture of the Browsers error and the excel file i am trying to load.

    The steps i am doing:

    1. i am using the Designer Components to load the excel file, attached to this post
    2. afterwards i have a Autosave function looking as follows:
    function autosave() {
        try {
            var designer = GC.Spread.Sheets.Designer.findControl(document.getElementById("gc-designer-container"));
            var spread = designer.getWorkbook();
            var spreadJsonObject = spread.toJSON(false, true, false, false, false);
            delete spreadJsonObject.namedStyles;
    
            var jsonObj = JSON.stringify(spreadJsonObject);
    
            $.ajax({
                url: '/Home/SaveSpread',
                type: 'POST',
                dataType: 'json',
                cache: true,
                data: {
                    json: jsonObj,
                    name: user
                },
                success: function (response) {
                    if (response) {
                        notify(dict.notify_autosave_complete[language], "success");
                    }
                }
            })
        } catch (err) {
            var x = err;
        }    
    }
    
    1. As soon as the code execute the toJSON function the spread freezes completly. I cant change anything anymore and cant load a different file as long as i dont refresh the page.

    This just happens with some specific Excel files and i dont know why. With other files it just works.

    I hope you can help me.

    Regards

    Maik

  • Posted 1 December 2021, 1:19 am EST

    Sorry i think i was to fast with posting. Here is the zip-file

    ErrorExcelFile.zip

  • Posted 1 December 2021, 9:55 pm EST

    Hi,

    We are sorry but we are unable to replicate the issue at our end. Could you please share a sample that replicates the issue so that we could investigate it further? You may also check the following sample that we used for testing and modify it to replicate the issue.

    sample: https://codesandbox.io/s/spread-js-starter-forked-9tx20?file=/src/index.js

    Regards,

    Avinash

  • Posted 6 December 2021, 9:49 pm EST

    Hey,

    for me it is happening in the sandbox aswell. I am just loading the xlsx from the zip and as soon as the autosave function is executed the spread completly freezes. Its just specific xlsx files. Some are working, but there are special ones, that won’t work.

    so i dont know how i can help to replicate it on your side.

    I could record a video on what happens on my side, if that helps.

    Regards,

    Maik

  • Posted 8 December 2021, 10:15 pm EST

    Hi,

    SpreadJS freezing for time would expected and depend upon the system configuration. Since the [provided file is large the toJSON method will take some time to complete at that time spreadJS may freeze.

    If you are implementing autoSave feature it would be better if instead of posting the complete JSON you may listen to various events and send information about changes it will boost the performance.

    For example, you changed the value of cell(3,3) from “john” to “john harper”, then send the changes to the server only about that cell. from “john” to “john harper” and also the row and column of the changed cell. something line we send

    { updates: [ {id: 3, changes: [ {columnName: “name”, newValue: “john harper”} ]} ] }

    this information can be found inside the CellChnaged event.

    For various events, please refer to the link:

    https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS~GC.Spread.Sheets.Events~_ctor.html

    Regard,

  • Posted 13 December 2021, 7:08 pm EST - Updated 3 October 2022, 12:29 am EST

    Hey,

    I think you get me wrong, when i say it freezes. Of course it freezes to do these actions, but no matter how much time went by, it stays frozen, because as you can see in the attached image, the toJSON function is throwing an error and can’t reach the resumePaint or resumeEvent function afterwards.

    It’s not specific for an autosave function it also happens, when u try the toJSON at the end of the edit process, to export it into our systems. In the attached image you see the same error happening without the later AJAX call.

    Regards,

    Maik

  • Posted 14 December 2021, 10:53 pm EST - Updated 3 October 2022, 12:29 am EST

    Hi,

    We are sorry but on our end, it is working fine. Could you please provide additional information such as browser info and system configuration so that we could test it in your environment?

    here is the gif of my observation

    Further, you may refer to the following sample and modify it to replicate the issue.

    Regards

    Avinash

    AutoSave_2021-12-15T10_27_25.zip

  • Posted 14 December 2021, 11:52 pm EST - Updated 3 October 2022, 12:29 am EST

    Hi,

    i replicated it with your sample. I am using Google Chrome and i’m on Windows 10 Pro N 21H1.

    Here is the gif of mine: (i forgot to show, that the spread is frozen after that error but it was)

    It seems like the normal toJSON() works but with arguments like i use toJSON(false, true, false, false, false) it returns with the error.

    Regards

    Maik

    AutoSave_from_GC.zip

  • Posted 15 December 2021, 10:30 pm EST

    Hi,

    Thanks for the information. However, We are still unable to replicate the exact error but we do observe that the spreadJS is freezing and becoming unresponsive.

    Since the toJSON syntax is incorrect it may behave differently please use the correct toJSON syntax and let me know if you face any issues.

    Following is the correct syntax of toJSON method.

    
      var spreadJsonObject = spread.toJSON({
          includeBindingSource: false,
          ignoreStyle: false,
          saveAsView: false,
          rowHeadersAsFrozenColumns: false,
          columnHeadersAsFrozenRows: false,
          includeAutoMergedCells: false,
        });
    
    

    API:

    toJSON:https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS~GC.Spread.Sheets.Workbook~toJSON.html

    Regards

    Avinash

  • Posted 15 December 2021, 11:33 pm EST

    Hey,

    the freezing is the main problem at the moment. I missread the toJSON function and now i dont get the error aswell, but as you now observe it freezes and becomes unresponsive. Even the resumePaint or resumeEvent doesn’t work here.

    The question now: is it an error on my side or is it just cause some third party Software exports an excel with additional information in background that spreadjs is unable to save?

    My current solution for files like this, is to copy the data in a new created Excel file and it works fine. But its not a good workflow for my clients. Is there any way to detect this and make this an automatic process?

    Regards

    Maik

  • Posted 19 December 2021, 7:46 pm EST

    Hey,

    Since you were using incorrect syntax to save the JSON it may be expected to give error and freeze based on the internal code. So it is reccomended use the correct toJSON method to save the JSON.

    Use the correct toJSON syntrax and let me knwo if you still face any issues.

    Regards

    Avinash

  • Posted 3 January 2022, 7:41 pm EST

    Hey,

    firstly i wish the Team a Happy new Year.

    As i tried to describe i am using the correct Syntax now and don’t get the Error message anymore, but it occures that it still freezes and becomes unresponsive in some way.

    As far as i know these are Excel-Files created from a third-party application my clients use. It may happen that this application add some additional data to the file, which is the cause why spreadJS freezes. I guess thats why the same “data” copied to a fresh excel file do not freeze it.

    Since i can’t find a solution to do a workaround and you can’t replicate this error on your side is there maybe an easy way to do the step i described automatically.

    So workflow would be:

    Open file →

    check if its a corrupt file (skip this, since i dont know if i can check whether the file is corrupt or not, without freezing spreadJS) →

    copy only the data of whole workbook to a new one and work with this afterwards.

    Regards

    Maik

  • Posted 5 January 2022, 10:40 pm EST

    Hi Maik,

    SpreadJS does not support excel files generated by third-party applications. Please share the excel files on which you are facing this issue so that we could investigate it further and help you accoridingly.

    Regards,

    Avinash

  • Posted 10 January 2022, 6:33 pm EST

    Hi Avinash,

    Its the same Excel File i already shared with you earlier in this topic. It’s just without any data, since i am not allowed to share this. There must be any data in the background that makes SpreadJS freeze with the toJson function.

    Since it’s working, when i copy the data in a new file, i only want to automatically copy data values only and make a “pseudo new file” to workarround this error.

    Regards,

    Maik

    ErrorExcelFile.zip

  • Posted 11 January 2022, 11:27 pm EST

    Hi Mark,

    We are sorry but we don’t have any tool that you could use to copy the data values only and create a new file.

    Further, if you want us to investigate the excel file for the exact issue then you could create a case on our private support portal and share the file with the data

    https://www.grapecity.com/my-account/my-support

    Regards

Need extra support?

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

Learn More

Forum Channels