SpreadJS FromJson Chart load

666 views Asked by At

I'm using SpreadJS v12 as a reporting tool. User will enter the page get the wanted data, create charts and save it for later use. When user saves the report I get Json data (GC.Spread.Sheets.Workbook.toJSon) and save this Json to database and whenever someone tries to reach the same report, I get the Json from database and give it to the page (GC.Spread.Sheets.Workbook.fromJSon). Everything works fine except if there is a chart on page the data source for chart series (xValues and yValues) change. When I check Json format it looks like this: Sheet2!$B$2:$B$25 but in chart it's: Sheet2!$A$1:$A$24 . Am I doing something wrong?

By the way my serialize options: { ignoreFormula: false, ignoreStyle: false, rowHeadersAsFrozenColumns: true, columnHeadersAsFrozenRows: true, doNotRecalculateAfterLoad: false }

this.state.spread = new GC.Spread.Sheets.Workbook(document.getElementById("spreadSheetContent"), { sheetCount: 1 });

This is my save method:

var pageJson = this.state.spread.toJSON(this.serializationOption);
let self = this;
        let model = {
            Id: "",
            Name: reportName,
            Query: query,
            PageJson: JSON.stringify(pageJson)
        }

        this.post( { model }, "Query/SaveReportTemplate")
            .done(function(reply){
                self.createSpreadSheet(reply);
           }).fail(function(reply){
                self.PopUp(reply, 4 );
        });

And this is my load method:

var jsonOptions = {
            ignoreFormula: false,
            ignoreStyle: false,
            frozenColumnsAsRowHeaders: true, 
            frozenRowsAsColumnHeaders: true,                                     
            doNotRecalculateAfterLoad: false 
        }

        this.state.spread.fromJSON(JSON.parse(template.PageJson),jsonOptions);

        this.state.spread.repaint();
1

There are 1 answers

0
xeon On BEST ANSWER

Well after a long day, I think I've found what's causing the problem and started working around that.

Let's say we have two sheets. Sheet1's index is 0 and Sheet2's index is 1. Because of the json serialization options like frozenColumnsAsRowHeaders and frozenRowsAsColumnHeaders until Sheet2 is painted row numbers and column number are different in the json.

If there is a formula or a chart in Sheet1 that's referencing Sheet2, their references will point to a different cell from what you set first. So always referencing the sheets that will be painted before is the way to solve this problem.