还有问题要问(WORD文档中某些已知字符串变成红色或者是加下划线)
我用以下的程序实现了上面的功能,可是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);
}
我把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);
}
...全文
相关推荐
C++程序中导出Word文档的简易方法
本文给大家介绍了C++程序中导出Word文档的简易方法。
C#采用OpenXml实现给word文档添加文字
主要介绍了C#采用OpenXml实现给word文档添加文字的方法,包括了用法的实例分析,是非常实用的技巧,需要的朋友可以参考下
[removed]把一段文字中指定字符颜色变成红色的正则
[removed]把一段文字中指定字符颜色变成红色的正则
asp生成带有样式的word文件方法
让asp生成带有样式的word文件,如字体颜色为红色,加粗,字号为36号的文字
python实现排序算法——冒泡排序
使用python实现冒泡排序算法,冒泡排序法是非常经典并且非常简单有效的排序算法。首先我们介绍一下冒泡排序算法。 算法步骤: Step 1: 比较第一个数和第二个数,如果第一个数比第二个数大,那么就调换两个数的位置。 Step 2: 按照step 1中的做法,依次比较序列中所有相邻的两个数。此时,序列中最大的数已经“沉”到了最后面。 Step...


