docx “File is corrupt” error in Microsoft Word

╄→гoц情女王★ 提交于 2019-12-23 12:18:48

问题


I wrote a program, which open docx package and changes some <w:t>-text in "word/document.xml". When i open new generated docx in Microsoft word, it gives me an error — "file is corrupted". But if look in "Open XML SDK Tool" diffs between template docx and result docx files — there is only two line changed in "word/document.xml". Look at screenshot:

Program doesn't touches document format, styles or smth. Only text in <w:t>

So, what's can provoke "file is corrupted" error in Microsoft Word?

And this error appears ONLY in Microsoft Word. For example OpenOffice and TextEdit on Mac OS X open generated files without any errors.

I upload these docx files, so you can look at them by yourself.


回答1:


I'd make a blind guess and say that the document you modified contains UNIX-style line endings. Word 2003 does not tolerate a \n line ending, it requires \r\n whereas Word 2007/2010 is more tolerant and accepts both versions.

Make sure to only use \r\n when modifying the document.

Update: I checked your document, and indeed the document XML part uses a UNIX-style line ending.

Update 2: You have an additional file included in your result document: .DS_Store. Remove that from the archive and the document will open.



来源:https://stackoverflow.com/questions/3547007/docx-file-is-corrupt-error-in-microsoft-word

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!