1

Okay, so this is a pretty generic and vague question, so please let me elaborate.

We have a large codebase which we are splitting up the past years to more individual self-contained libraries.

One of the larger and more unwieldy parts is our Word export module. It uses docx4j currently, however we run into memory issues with large exports with a lot of pictures. Besides that, it is pretty difficult to update the exporter due to changes in our domain model.

It has been a while since someone worked on it (like years...) so I took it upon myself to investigate the state of generating Word documents in 2021. I hoped a lot had changed, but some Google searches let me to posts of 2010, and libraries of 2012. Of course, it can be the case that a library of 2012 means it is just that good.

I have identified the following solutions, though I am probably missing a lot:

  • Docx4j (JVM), still maintained, we run into memory problems with that.
  • Docx4j with Content Control Data Binding. Seems to be some way to use templating?
  • Apache POI (JVM), have some okay experience with the Excel part, no experience with the Word part. The 'consensus' online appears to be that Docx4j is more user-friendly.
  • JasperReports. Don't know anything about that.
  • DocX, .NET library, no experience.
  • Office Add-In using Office.js (JS). Official API from Microsoft. Runs at client in Word, so required connection to an API.
  • docxtemplates (Node / Browser). No experience. Looks complete, don't know about performance though.
  • officegen (Node). Last release 2019.
  • Carbone (node). https://github.com/Ideolys/carbone. No experience also.
  • probably more...

So, as expected a lot of libraries in JS popping up as well.

Looking at my requirements:

  • using a template would be nice
  • running it as a service would be nice
  • efficient (memory wise, don't mind if it takes some time to generate)

We have quite a good JSON API available, which is very easy to maintain and maps pretty good to our domain model. My preference would be to use that as a source of course.

what are peoples experiences and/or am I missing some very good libraries out there?

1

For generating templates have a look at the Perl module MsOffice::Word::Template which is recent. To run it as a service, you could easily plug that into a Mojolicious webserver which also runs the Minion job queue to keep your server from getting flooded.

0

There is the Python docx library which can be run successfully on machines that do or do not have Microsoft word installed so is well suited to running in a back-end on a server, etc.

However, have you thought of moving away from targeting specifically word documents - the Sphinx toolchain can target producing, from a single set of inputs, HTML (including Windows HTML Help), LaTeX (for printable PDF versions), ePub, Texinfo, manual pages, plain text. This would give you a lot of flexibility and it might be a good time to consider moving away from a Word based document set.

1
  • Thanks for your reply. Sadly our customers really like Word. It is for exports in their company. But ill look into the Python lib! Feb 8 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.