还有问题要问(WORD文档中某些已知字符串变成红色或者是加下划线)

elixir2002 elixir2002 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我用以下的程序实现了上面的功能,可是WORD标注的过程会在前台显示出来,能不能让这个过程在后台进行,不显示出来,
我把myWordApp.Visible =false也还是不行
如何实现,谢谢大家了,!!!
private void WriteFile()
{

strFileName=@"c:\try.doc";
Object Nothing=System.Reflection.Missing.Value;
object isVisible = false;
myWordDoc=myWordApp.Documents.Add(ref strFileName,ref Nothing,ref Nothing,ref isVisible);
object readOnly = false;
object missing = System.Reflection.Missing.Value;
string text="";
myWordApp.Visible =true;
textBox1.Text =myWordDoc.Content.Text;
Word.Find find = myWordApp.Selection.Find;
find.ClearFormatting();
object FindText = "上报成功";
object MatchCase = false;
object MatchWholeWord = true;
object MatchWildcards = false;
object MatchSoundsLike = false;
object MatchAllWordForms = false;
object Forward = true;
object Wrap = Word.WdFindWrap.wdFindStop;
object Find_Format = false;
object ReplaceWith = "";
object Replace = Word.WdReplace.wdReplaceNone;
object MatchKashida = false;
object MatchDiacritics = false;
object MatchAlefHamza = false;
object MatchControl = false;
while(find.Execute(ref FindText, ref MatchCase, ref MatchWholeWord, ref MatchWildcards, ref MatchSoundsLike,
ref MatchAllWordForms, ref Forward, ref Wrap, ref Find_Format, ref ReplaceWith, ref Replace, ref MatchKashida,
ref MatchDiacritics, ref MatchAlefHamza, ref MatchControl))
{
myWordApp.Selection.Font.Color = Word.WdColor.wdColorRed;
find.ClearFormatting();
}

#region 将数据库中读取得数据写入到word文件中


DateTime iNow=DateTime.Now;
string strDate=iNow.ToString();
strContent=strDate;
WriteFile(strContent);
#endregion
//将WordDoc文档对象的内容保存为DOC文档
myWordDoc.SaveAs(ref strFileName,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing);
//关闭WordDoc文档对象
myWordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
//关闭WordApp组件对象
myWordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
}


...全文
评论 12
收藏 已收藏
分享
返回顶部
elixir2002
C# 111,129 成员 642,540 内容