Saving styles to JSON makes it too large

Posted by: k.szabariova on 30 July 2021, 12:26 pm EST

    • Post Options:
    • Link

    Posted 30 July 2021, 12:26 pm EST

    Hello,

    I noticed if I crate a sheet of let’s say 100x500 cells and style most of the cells with some font color, background, maybe border etc, the resulting JSON, coming from spread.toJSON operation is super large, often over 1MB.

    That becomes a problem since AWS Lamba have limit on payload 6MB.

    Upon inspecting the JSON I noticed the library saves a styles to every single cell. Which is understandable, however very ineffective - it’s always same few styles written over and over again for every cell.

    Is there a remedy for my problem? Some kind of compression of style saving?

    Thanks!

  • Posted 2 August 2021, 7:01 am EST

    Hi,

    This is a known issue and we are working on improving this behaviour but currently, we do not have an ETA for the same(Internal tracking IDs: SJS-5772, SJS-7264).

    Till then you may use the named styles. Please refer to the following code snippet:

    var style = new GC.Spread.Sheets.Style();
    style.backColor = "red";
    style.name = "m_red"
    spread.addNamedStyle(style);
    for(var i=0;i<20;i++){ 
     sheet.setStyleName(i,0,'m_red');
    } 
    

    The basic idea is that when styles are added as named styles then only a single style object is exported and cells store only the style names.

    Regards

  • Posted 3 August 2021, 3:54 pm EST

    Thank you sharad, I’ll look into this.

    For time being I implemented compressing the JSON which decreases it’s size about 15x. Using pako.deflate(string). That’s helpful.

Need extra support?

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

Learn More

Forum Channels