docx created with word online
See original GitHub issueIf I create a docx in SharePoint it takes me to Word Online. I add some text and it saves automatically. Then I download the file.
Now I do the following:
import zipfile
zip = zipfile.ZipFile('path/to/file.docx')
xml = zip.read('word/document.xml')
This fails with KeyError: "There is no item named 'word/document.xml' in the archive"
There is, however, a ‘word/document2.xml’ which contains (at least for my one trial case) the same as ‘word/document.xml’. I discovered this by opening ‘path/to/file.docx’ in actual Microsoft Word on my local machine and then saving the file. NOW when I do zip.read('word/document.xml') the xml file is there as expected.
I really don’t know much about this stuff or why creating a file with Word Online appears to create something different then local Word. Thus I don’t know what the best solution is. It seems hack-ish to just put a line in the code that says if you can’t find ‘word/document.xml’ look for ‘word/document2.xml’ but maybe that’s all we need. Let me know.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
Top Related StackOverflow Question
Yep, @fjouault I’ve updated my PR to reflect this. As far as I can tell this solution is robust. I’d appreciate any help with manually testing it, but hopefully this is ready to merge (or at least very close).
I’m getting this issue and a temporary fix I created is as follows:
Basically I replace the hard coded xml (line 87) with a regular expression search as highlighted above. We are doing it in this way because the environment is containerized so every time we need to reinstall the package and change this line. For those who run this in their own long-lasting environment, simply replace line 87 with the following:
It’s definitely not perfect and can be improved… but anyway it solves my problem 😃