How to give multiple named styles to a single cell?

Posted by: shanmukha.vangaru on 30 June 2021, 12:07 am EST

    • Post Options:
    • Link

    Posted 30 June 2021, 12:07 am EST

    Hi,

    I am having a scenario where I will load the spreadsheet using the fromJson method and I need to give multiple named styles to a single cell as shown in the below example.

    Consider the following json.

    “sheets”: {

    “Sheet1”: {

    “data”: {

    “dataTable”: {

    “0”: {

    “0”: {

    “value”: “some value”,

    “style”: [“STYLE1”, ""STYLE2] // Is there a way to achieve this functionality ?

    }

    }

    }

    }

    }

    },

    “namedStyles”: [

    {

    “name”: “STYLE1”,

    // some styles

    },

    {

    “name”: “STYLE2”,

    // some styles

    }

    ]

    Regards,

    Shanmukha Vangaru

  • Posted 30 June 2021, 4:02 am EST

    Hi,

    We are sorry this is not supported in SpreadJS. What we could do is combined the styles objects and set the newStyle to Cell. Please refer to the following code snippet and attached sample that demonstrates the same.

    
     document.getElementById("add").addEventListener("click", (e) => {
        let newStyle = style1.clone();
        newStyle = clonedStyle(newStyle, style2);
        sheet.setStyle(0, 1, newStyle);
      });
      function clonedStyle(style, style2) {
        Object.keys(style2).forEach((key) => {
          style[key] = style2[key];
        });
        return style;
      }
    
    

    sample: https://codesandbox.io/s/fast-river-rh7m3?file=/src/index.js

    Regards

    Avinash

Need extra support?

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

Learn More

Forum Channels