dolanmiu / docx

Easily generate and modify .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.
https://docx.js.org/
MIT License
4.44k stars 486 forks source link

Compatability issues when uploading to Microsoft Word Online #496

Open willmccullough opened 4 years ago

willmccullough commented 4 years ago

The last couple of days I've been trying my best to get this library to work for Word Online. After searching Google, the issues here, and a lot of troubleshooting, I figured I'd open an issue. At the moment there are two issues that make this library a deal breaker for Word Online (at least for me).

1. Images added to a docx generated document render as empty squares in Word Online.

I didn't run into this issue when using Word on Windows desktop or Libre Office. n fact, loading the docx generated document into the desktop version of Word and saving it fixes the issue. The lead me to compare the differences between the XML contents of the copy that didn't work and the one that did. The only significant difference was the naming conventions for the PNG files in the /word/media directory.

docx generates file names that look like a hash or an unique id while Word desktop generates image${n}.png. (e.g., image1.png, image2.png...). When I renamed the broken copy's files to follow this convention (and updated document.xml.rels), the pictures successfully appeared in Word Online. Is there any chance you would consider making the media file naming convention a setting for the main document object?

2. I can't edit/save a docx generated document in Word Online.

I tried my best to find out what was causing this issue, but I have yet to do so. As with issue #1 this only happens on Word Online, I had no issues with Word on Windows desktop or Libre Office.

All of this said, do you plan on doing more testing with these features with Word Online, or are you more concerned with the desktop applications? I wouldn't mind working on a pull request if you're interested in improving Word Online compatibility.

dolanmiu commented 4 years ago

Thanks for all this research, this is very valuable

docx generates file names that look like a hash or an unique id while Word desktop generates image${n}.png. (e.g., image1.png, image2.png...)

At the moment, the IDs are generated with shortid: https://www.npmjs.com/package/shortid

shortid is able to create numeric only ids, do you think this would work?

so e.g.... image35345.png

It is done this way because keeping track of a counter like currentImageCounter is messy. Especially when you need currentHyperlinkCount, currentRelationshipCount etc for every id.

willmccullough commented 4 years ago

@dolanmiu I will test the image id pattern you mentioned sometime this week and, if it works, submit a pull request.

mike-lipin commented 3 years ago

I have the same second issue. Trying to understand the reasons I opened the generated docx in MS Word and then just saved the docx and then compared the outputs. The saved from Word got more source files than it was generated in the first place. Could you explain why? Can it be the reason? before-after-resave

LikeCarter commented 3 years ago

Version 5.5 still seems to work with MS Online