0
votes

I have an xml file with just a worksheet in it that is being rendered with reportjs. There are many of these separate xml files for different reports that are being generated and every single one has it's own <styleSheet> tag with a bunch of duplicated code.

In this format:

<worksheet>
   ...custom report...
</worksheet>
<styleSheet>
   ...tonnes of duplicated styling...
</styleSheet>

I want to pull that <styleSheet> code into a separate file and create a standard set of styles that I can then import into each report.

I have tried:

<!DOCTYPE doc [
<!ENTITY customStyles SYSTEM "./style.xml">
]>
&customStyles;

where &customStyles is in many places with no luck and I have also tried using many of the jsreport features with no luck.

How can I simply inline import a stylesheet into each of these reports?

3

3 Answers

1
votes

This is task for jsreport asset. Upload the stylesheet xml as an asset and use xlsxReplace to add it to particular template.

{{#xlsxReplace "xl/styles.xml"}}
    {#asset style.xml}}
{{/xlsxReplace}} 

{{#xlsxAdd "xl/worksheets/sheet1.xml" "worksheet.sheetData[0].row"}}
    <row>
        <c t="inlineStr" s="1"><is><t>Hello world</t></is></c>
    </row>
{{/xlsxAdd}}

{{{xlsxPrint}}}

The playground example can be found here.

0
votes
  1. You need to load your loaded source file.
  2. Create a separate stylesheet for that file and save it to the sheet.
  3. Apply individual styles to your cell.
0
votes

Here is what I ended up doing:

I was already reading the xml file, getting it's content, and rendering it with

fs.readFile(templatePath, 'utf8', function(err, content){
...
}

So I just extracted the styles into a new document, nested some read files and concatenated the results.

fs.readFile(templatePath, 'utf8', function(err, content){
    fs.readFile(stylesPath, 'utf8', function(err, styles){
        ...
        content: `${content}{$styles}`
    }
}