alanhay / html-exporter

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

Charts and graphs #28

Open chrisco484 opened 6 months ago

chrisco484 commented 6 months ago

Looks like a great library - I could have done with something like these 5 years ago when I had to generate some reports in Excel - ended up using raw POI back then but generating from HTML would have been a lot nicer.

Is there any way of inserting charts or graphs into an Excel file using html-exporter or do you have any hints as to how I might enhance html-exporter to support that?

alanhay commented 6 months ago

Hi. There is no direct way in the library. I believe POI supports directly creating at least some charts now but haven't used it and don't know how extensive it is.

Prior to this you could do charts by defining them in an Empty excel work book based on ranges and then populating the data using POI i.e. by loading and populating that existing workbook: POI maintains any existing charts, VBA code etc. in that workbook. I have used that approach (a long time ago) and it worked as advertised.

I don't really see any way to export a chart from HTML to POI so that is probably the best option here. Create a workbook with some charts defined on some dynamic data range > use that workbook as a template i.e. modify html-exporter to load an existing workbook > populate it using html-exporter.

chrisco484 commented 6 months ago

That's a good suggestion. I'll give that a go, thanks.

chrisco484 commented 6 months ago

On another note:

I actually made a fork and merged in the changes on the fusionnx fork (because it adds support for specifying font sizes with 'pt' suffix etc., and I had a lot of existing external .css files I wanted to use that used 'pt' for font sizes.

However the main purpose of my fork was to add support for external .css files via <link .. > tags.

It seems to be working well for me. It works under a couple of constraints:

The core addition is the IResourceLoader interface which the user must supply an implementation for.

The changes are in this commit:

https://github.com/chrisco484/html-exporter/commit/3249e844d2b5796810ea06e6a50f0b9d4670af3c

I can raise a pull request if you like but it's going to include the changes from the fusionnx fork if that's ok.

alanhay commented 6 months ago

Hi. Yes, sounds useful. Feel free to raise a PR and I will review it when I have a minute.

Thanks.

Alan