Exporting HTML (with images & tables) to Word (.doc/.docx) in Retool custom component

Hi ,

I am trying to build a custom component that can take HTML content from my app (including images, tables, and styled text) and export it as a downloadable Word document (.doc / .docx) to local storage.

I have tried different approaches:

  1. Wrapping HTML in a .doc MIME type β†’ works for simple text, but not a real .docx.
  2. Using the docx NPM library β†’ generates valid .docx, but it strips out most HTML formatting (tables, images, bold/italic, etc.).
  3. Using html-docx-js β†’ preserves formatting, but when I include images (hosted on Retool Storage with signed URLs), they appear as broken links (cross icon) inside Word instead of displaying correctly.

My challenges:

  • Need to generate a valid Word file (.doc or .docx) directly from HTML.
  • Preserve images and tables from the original HTML (images are uploaded in Retool storage).
  • File should be downloaded to local storage after export.

Here’s a screenshot of the issue when opening the Word file:

Has anyone found a reliable way to handle this? Or is there a recommended Retool-compatible library / workflow for exporting full HTML (with images + tables) to Word?

1 Like

Hello @Laiba_Saleem,

In order to properly investigate and resolve the issue, could you please provide the following:

  1. Demo App JSON – This will help us replicate the environment and test the behavior directly.
  2. Custom Component Code – Reviewing the implementation will allow us to identify any possible configuration or logic errors.

Additionally, I noticed that your component is referencing certain links. Please verify whether these are public URLs. If they are private, the images or other resources may not be accessible through third-party libraries, which can result in them not displaying correctly. To avoid this problem, ensure that the URLs are publicly accessible before integrating them into your code.

Once you share the JSON, the component code, and confirm the accessibility of the URLs, we will be able to analyze the setup in detail and provide you with accurate guidance on resolving the issue.

1 Like

I think you need to use altChunk elements for HTML within a doc/docx file. Here's a StackOverflow thread that's related: openxml - Insert HTML in docx file - Stack Overflow

2 Likes

Hi @Laiba_Saleem,

This functionality isn't natively supported but you may be able to a workaround. I think @bobthebear is on to something with his links. Let us know if altChunk or openxml works.

Hi @Laiba_Saleem,

Just wanted to follow up and see if Bob’s link for setting up the code to get this functionality via a work around was helpful to you!

i’ve created a library for which i think can help you with your issue html-docxjs-compiler. You can take a look to see if its suitable for fixing your problem.