5

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:

enter image description here

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 Answer 1

4

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.

2
  • Microsoft Office 2010 gives same error with "result.docx" — "file is corrupted". Also, i fixed UNIX-style line endings in document.xml with unix2dos command-line utility, and still no luck, same error appears. Any ideas?
    – nukl
    Aug 23, 2010 at 12:50
  • Notice. Word 2007 doesn't accept \n line ending in pkg:binaryData element, while Word 2010 does.
    – ruvim
    Apr 18, 2015 at 22:54

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.