# How to add some texts into Microsoft Word file in a specify place

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.


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

• 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. – J. M.'s ennui Sep 5 '17 at 2:44
• @J.M. After I save it as .xml,then I import some XMLObject.That's confusing.. – yode Sep 5 '17 at 2:56
• Yes, that's why I'm questioning you if it is really needed to deal with *.docx instead of, say, *.txt. – J. M.'s ennui Sep 5 '17 at 2:58
• @J.M. Maybe this is what you want to tell me. – yode Sep 5 '17 at 3:16
• 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). – J. M.'s ennui Sep 5 '17 at 3:24

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"]
Export["file2.xml",
Replace[file,
"This is second line." :> "This is second Some Text line.",
Infinity]]


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.