alanhay / html-exporter

Java Library to convert HTML/CSS to MS Excel and ODS Spreadhseets.
Apache License 2.0
35 stars 38 forks source link

Support external .css files via <link .../> elements in HTML <head> element + all enhancements from the fusionnx fork #29

Open chrisco484 opened 8 months ago

chrisco484 commented 8 months ago

Some HTML is produced by tools which do not 'auto embed' the contents of #include files into the generated source but assume that the HTML processor will be able to include .css files added via <link .. /> elements in the header at processing time. Previously html-exporter was not such a HTML processor but with this enhancement, by setting an IResourceLoader, html-exporter is capable of handling external .css files specified in <link ../> elements within the element.

The demo report.vm includes a file called report.css - this was not a "well formed" .css file because its contents were wrapped within:

<style>
...
</style>

Note: With support for external css files the report.css file needed to be a "well formed" .css file so the wrapper has been removed from the .css file and placed within the report.vm file. This means that the new demo file report-external-css.vm can share this report.css file.

The inclusion of external .css files is facilitated with an implementation of IResourceLoader that must be supplied by the user of the html-exporter library so that implementation is completely up to the user. The IResourceLoader implementation must be set via:

excelExporter.setResourceLoader(resourceLoader);

prior to calling:

excelExporter.exportHtml(...)

A sample implementation is provided in the ../demo/ReportGeneratorExternalCss.java file.

Also - includes the changes from the fusionnx fork which add support for size attributes that have trailing suffixes like 'pt', 'px', '%' etc.,