views:

136

answers:

1

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 — http://img.skitch.com/20100823-1dxncq6fh33iew87wkdp63bbn4.png . 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 — http://bit.ly/cPlTjd

thanks.

+2  A: 

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.

0xA3
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?
cru3l
yeah, now it works. Thanks a lot!
cru3l