Use asp.net to replace Word in batches, and use asp. netword to replace Word.
First, the Microsoft. Office. Interop. Word component is introduced, which appears in COM after the office is installed.
The Code is as follows:
Using System; using System. collections. generic; using System. diagnostics; using System. linq; using System. text; namespace TextReplace {public class WordOperate: IDisposable {private Microsoft. office. interop. word. _ Application _ app; private Microsoft. office. interop. word. _ Document _ doc; object _ nullobj = System. reflection. missing. value; // <summary> /// close the Word Process /// </summary> public void KillWinword () {var p = Process. getProcessesByName ("WINWORD"); if (p. any () p [0]. kill ();} /// <summary> /// Open the Word document /// </summary> /// <param name = "filePath"> </param> public void Open (string filePath) {_ app = new Microsoft. office. interop. word. applicationClass (); object file = filePath; _ doc = _ app. documents. open (ref file, ref _ nullobj, ref _ nullobj, ref _ nullobj );} /// <summary> /// Replace the text in word /// </summary> /// <param name = "strOld"> Search Text </param> // /<param name = "strNew"> replaced text </param> public void Replace (string strOld, string strNew) {_ app. selection. find. clearFormatting (); _ app. selection. find. replacement. clearFormatting (); _ app. selection. find. text = strOld; _ app. selection. find. replacement. text = strNew; object objReplace = Microsoft. office. interop. word. wdReplace. wdReplaceAll; _ app. selection. find. execute (ref _ nullobj, ref _ nullobj, ref _ nullobj, ref objReplace, ref _ nullobj, ref _ nullobj );} /// <summary> /// Save /// </summary> public void Save () {_ doc. save () ;}/// <summary> /// exit /// </summary> public void Dispose () {_ doc. close (ref _ nullobj, ref _ nullobj, ref _ nullobj); _ app. quit (ref _ nullobj, ref _ nullobj, ref _ nullobj );}}}
The above is all the code about how asp.net operates Word to implement batch replacement. I hope it will be helpful for you to learn.