how to set cell value and preserve cell formatting



  • I'm using an xlsx template with cells formatted with background colors and border styles. When I run this code, it clears out the formatting. How can I preserve the formatting from the xlsx template?

    {{#xlsxReplace "xl/worksheets/sheet1.xml" "worksheet.sheetData[0].row[0].c[6]"}}
        <c t="inlineStr"><is><t>{{PRJ_NAME}}</t></is></c>
    {{/xlsxReplace}}


  • Unzip the xlsx template and check the xml. The cell will contain an s attribute specifying the style and you should add the same.
    Something like

    <c t="inlineStr" s="xxx"><is><t>{{name}}</t></is></c>
    


  • I'm having a curious problem using the s attribute. If I use a style on a cell that doesn't already use that style in my template, no problems - it works as expected. But if I use the style on a cell that already had that style in the template, that cell appears to lose the style.

    I've uploaded an example here https://playground.jsreport.net/w/steraji/zpfH_uwE
    where I set cells A1-F1 to a value with style 26 (yellow background). In the template, F1 is the only cell in that range that already had style 26 applied to it, and it's the only one that isn't yellow. I downloaded & unzipped the file and found that A1-F1 all had the style.



  • You have on this particular cell conditional formatting enabled. If I remove it, I get the cell yellow.



  • D'oh! I'm such a newbie :P
    Thank you :)


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.