elixir2002 2005年03月23日
还有问题要问(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);
}


...全文
290 点赞 收藏 12
写回复
12 条回复

还没有回复,快来抢沙发~

发动态
发帖子
C#
创建于2007-09-28

8.4w+

社区成员

64.0w+

社区内容

.NET技术 C#
社区公告
暂无公告