usingSystem;usingSystem.IO;usingSystem.Reflection;usingMword =Microsoft.Office.Interop.Word;namespaceconsoleapp3{classProgram {Static voidMain (string[] args) {mword.application app=NewMicrosoft.Office.Interop.Word.Application (); Mword.document Doc=NULL; ObjectUnknow =Type.Missing; App. Visible=true; stringstr =@"F:\2.doc"; ObjectFile =str; Doc= App. Documents.Open (reffile,refUnknow,refUnknow,refUnknow,refUnknow,refUnknow,refUnknow,refUnknow,refUnknow,refUnknow,refUnknow,refUnknow,refUnknow,refUnknow,refUnknow,refunknow); //loop out all content for(inti =1; I < Doc. Paragraphs.count; i++) { stringtemp =Doc. Paragraphs[i]. Range.Text.Trim (); Console.WriteLine (temp); } ObjectBK ="Telephone";//Word bookmarks if(Doc. Bookmarks.exists ("Telephone") ) {doc. Bookmarks.get_item (BK). Range.Text="Insert Text";//Insert Text} console.readkey (); } }}
C # reads Word and inserts text at the specified location