简体   繁体   中英

How can I edit and save correct OpenXML docx file?

I parse document.xml(change file.docx name to file.docx.zip and uznip it) file manually and put my code:

<w:r>
      <w:t>new text</w:t> 
</w:r>

instead of

<w:r>
      <w:t>text</w:t> 
</w:r>

and then I save it into zip-archieve(and change file.docx.zip name to file.docx) and try to open docx with MSWord 2013. But I get error by Word - incorrect document. How to fix it ? Thank you.

Why are you doing it manually? I used the Open XML SDK and it worked smoothly.

You have basically access to the whole xml tree so you can change almost anything you want, with the exception that the library takes care of zipping and unzipping.

The SDK has also a viewer where you can have a better look at the file, and what I've found is that most docx documents have internally multiple files zipped together. Maybe you are missing one of them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM