Skip to content
foglcz edited this page Apr 23, 2013 · 14 revisions

So.. How this works?

Knowing all the procedures, syntax and process of how-to is nice. But that's nothing when you want to actually implement this library into your system. So how does this work?

Suppose you have following files:

  • static.xsl with your static assets (see second chapter)
  • template.xsl with your actual transformation - the one that calls generate_excel template
  • data.xml with your data (eg. data from database, in our case)
  • picture.jpg with the picture, you want to have added into final excel

Then, there's couple of options. First, the easiest is to extract all files into same folder and run transform saxon parser on the template.xsl.

When you run this (see one of the examples in showcase directory) it will produce valid internal structure of an excel file. With one exception - the binary file picture.jpg will be just blank file.

So, after finishing the transformation, we loop through binary files we have (in this case that would be picture.jpg only) and copy them into respective places where we find the file with the same name.

Afterwards, we just zip it.

Implementation into existing systems

So wrapping up the implementation into bullet points, we work as follows:

  1. Extract all .xsl related content into tmp directory
  2. Put the data.xml into tmp directory
  3. Put all binary assets that might be used into tmp/binaries directory
  4. $ cd tmp/output && transform -xsl:../template.xslt -s:../data.xml (modify the command to your needs)
  5. Loop everything we have in tmp/binaries and search for those files within tmp/output. If any of the files is found, replace the output file with the one from binaries directory
  6. cd tmp/output && zip -m -r report.zip * && mv report.zip report.xslx

And that's essentially it!

Hacking saxon

If you're Java programmer, you can build your own UriResolver for Saxon. In the URI resolver, you could look for the binary file and have saxon handle it by default.

Note that, I cannot confirm nor deny this, as I was not responsible for saxon implementation. All I am is an XSLT user - therefore, all I do is to have result-document touch the binary file and our parsing engine takes care for the rest. I have no idea how, though.

Missing section?

There might be more to this. Feel free to report any discrepancies and/or any suggestions to this section or the guide using issues on github , or just send me an e-mail

Navigation

  1. Preparing excel files
  2. Preparing the first output
  3. Putting plain data into excel sheet
  4. Appending images
  5. Creating multiple worksheets
  6. Printer settings
  7. Macro-enabled workbooks
  8. Under the hood
  9. Engine parameters documentation
  10. Best practice for writing Excel XML
  11. Authors, license, contributing