Such as I have a office word file named file.docx.It have some text in it,Such as

I have a dfj.
This is second line.
Ok. I know that already.

Then I want to add some string into the place that the arrow pointting by MMA.Is it possible?

  • $\begingroup$ Does it really have to be a *.docx file? The format is quite complicated (essentially a zipped bunch of XML files) that maybe a text file would be less of a headache. $\endgroup$ Commented Sep 5, 2017 at 2:44
  • $\begingroup$ @J.M. After I save it as .xml,then I import some XMLObject.That's confusing.. $\endgroup$
    – yode
    Commented Sep 5, 2017 at 2:56
  • $\begingroup$ Yes, that's why I'm questioning you if it is really needed to deal with *.docx instead of, say, *.txt. $\endgroup$ Commented Sep 5, 2017 at 2:58
  • $\begingroup$ @J.M. Maybe this is what you want to tell me. $\endgroup$
    – yode
    Commented Sep 5, 2017 at 3:16
  • $\begingroup$ As I mentioned, a *.docx file is essentially a *.zip file in disguise; so, you might need to do something like Import["file.docx", "word\\document.xml"] (unfortunately I do not have Office or a *.docx file for testing). $\endgroup$ Commented Sep 5, 2017 at 3:24

1 Answer 1


As this comment,I realize I can Save As my .doc file into .xml file.Then process it

file = Import["C:\\Users\\zyd199012\\Desktop\\file.xml"]
  "This is second line." :> "This is second Some Text line.", 

Then Save As it back into .docx file. Of course,if someone know how to use MMA convert the .docx file into a .xml file,the answer is expected still.


Your Answer

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

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