Search code examples
xmlopenxmlworksheetjsreport

OpenXML import xml stylesheet into xml worksheet?


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?


Solution

  • 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}`
        }
    }