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

elixir2002 2005-03-23 11:56:02
我用以下的程序实现了上面的功能,可是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);
}


...全文
411 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
elixir2002 2005-03-29
  • 打赏
  • 举报
回复
我看了athossmth(athos) 的这段,可是还是不行
elixir2002 2005-03-28
  • 打赏
  • 举报
回复
是在winform下的一个程序
elixir2002 2005-03-28
  • 打赏
  • 举报
回复
?
athossmth 2005-03-27
  • 打赏
  • 举报
回复
哦,如果连server上都不要出来,或者这是一个winform,可以这样做:

Object[] objMissing = new Object[1];
objMissing[0] = System.Reflection.Missing.Value;

Type WordType;
Object WordApp;

WordType = Type.GetTypeFromProgID("Word.Application");
WordApp = Activator.CreateInstance(WordType);

Object[] objFalse = new Object[1];
objFalse[0] = false;
WordType.InvokeMember("Visible", BindingFlags.SetProperty, null, WordApp,objFalse);

这样就没有word窗口了。
athossmth 2005-03-27
  • 打赏
  • 举报
回复
这个是code behind,本来就在server端运行,用户是看不到的。
elixir2002 2005-03-27
  • 打赏
  • 举报
回复
是这个意思,就是不想让WORD操作的这个过程出来
hamadou 2005-03-26
  • 打赏
  • 举报
回复
楼主好象是说不想让word程序的主窗口显示出来,对吗?
syeerzy 2005-03-26
  • 打赏
  • 举报
回复
我也没看明白要干什么
hivak47 2005-03-26
  • 打赏
  • 举报
回复
不明白楼主什么意思。
elixir2002 2005-03-26
  • 打赏
  • 举报
回复
up
elixir2002 2005-03-23
  • 打赏
  • 举报
回复
谢谢
corbet 2005-03-23
  • 打赏
  • 举报
回复
第一个帮你顶!

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧