标签:users document int select match 打开 ocx ring 文件名
using MSWord = Microsoft.Office.Interop.Word;
MSWord.Application app = null;
MSWord.Document doc = null;
//将要导出的新word文件名
string physicNewFile = @"C:\Users\HYYX\Desktop\上行20180608\模板\深圳正大康F-HLH-2网内干扰分析报告.docx";
app = new MSWord.Application();//创建word应用程序
object fileName = (physicNewFile);//模板文件
//打开模板文件
object oMissing = System.Reflection.Missing.Value;
doc = app.Documents.Open(ref fileName,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
object replace = MSWord.WdReplace.wdReplaceAll;
app.Selection.Find.Replacement.ClearFormatting();
app.Selection.Find.MatchWholeWord = true;
app.Selection.Find.ClearFormatting();
app.Selection.Find.Text = "根据干扰源定位分析结果,深圳正大康F-HLH-2网内干扰优化方案制定如下:(待补充)";//需要被替换的文本
app.Selection.Find.Replacement.Text = "根据干扰源定位分析结果,深圳正大康F-HLH-2网内干扰优化方案制定如下:"+"\r\n"+textBox27.Text;//替换文本
//执行替换操作
app.Selection.Find.Execute(
ref oMissing, ref oMissing,
ref oMissing, ref oMissing,
ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref replace,
ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
//对替换好的word模板另存为一个新的word文档
doc.SaveAs(@"C:\Users\HYYX\Desktop\上行20180608\模板\深圳正大康F-HLH-2网内干扰分析报告1.docx",
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
//关闭wordDoc文档
app.Documents.Close(ref oMissing, ref oMissing, ref oMissing);
//关闭wordApp组件对象
app.Quit(ref oMissing, ref oMissing, ref oMissing);
基于Microsoft.Office.Interop.Word的替换文字
标签:users document int select match 打开 ocx ring 文件名
原文地址:https://www.cnblogs.com/SiSui/p/9506059.html