privateOmega / html-to-docx

HTML to DOCX converter
MIT License
375 stars 141 forks source link

Downloaded documents cannot be open and message: "Word experienced an error trying to open the file..." appears #249

Open ocelph opened 1 month ago

ocelph commented 1 month ago

Hi! So, I am using node.js v22, and using html-to-docx v1.8.0 to convert an html page to docx format. This docx file can then be downloaded when I activated the download button. There are several button and each are for different content. The content is all there as i can see it in the preview however, every time I try to open in I get the following error:

Word experienced an error trying to open the file. Try these suggestions.

  • Check the file permissions for the document or drive.
  • Make sure there is sufficient free memory and disk space.
  • Open the file with the Text Recovery converter.

My coworker have also try to download the files but we keep getting the same error. We also tried to lower the node version to v16 but the problem persisted. (This is happening on Linux and MacOs)

If you have a solution or any idea of why this could be happening please let me know!

leafnx commented 1 month ago

Hello, I encountered the same problem (node.js v16, html-to-docx v1.8.0). For me this seems to occur only in desktop MS Word, but in WordPad, google docs and MS Word online (Microsoft 365) everything works fine. Also I can still open a file in desktop MS Word if I open it in read-only mode manually. Hope it helps.

shawnthompson commented 1 month ago

We were / are using html-docx-js but switching to html-to-docx and having the problem with both packages. We seemed to have fixed the problem by getting it to create a temporary html file first to a folder on the drive and then converting that file to a docx file, then allowing the user to download it from our app.

See the PR here, using html-docx-js: create temporary file for Word generator by shawnthompson · Pull Request #71 · aaact-aatia/a11y-ict-wizard.

Now I'm working on switching to html-to-docx, and it works.