问题请教,我从对话框往已有word里写入数据,怎么实现让word不在屏幕上打开啊,
有个问题请教一下,,我从对话框往已有word里写入数据,怎么实现让word不在屏幕上打开啊,
Word.Application app = new Word.Application(); //可以打开word程序
Word.Document doc = new Word.Document(); //一会要记录word打开的文档
Object fileName = @path + "\\tianxie\\core.doc";
Object nullobj = System.Reflection.Missing.Value;
//String fileContent = "";
try
{
app.Visible = true;
doc = app.Documents.Open(ref fileName,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
// fileContent = doc.Content.Text;
// MessageBox.Show(fileContent);
Word.Bookmark bookmark1 = doc.Bookmarks["s_1001"];
bookmark1.Range.Text = str6;
Word.Bookmark bookmark2 = doc.Bookmarks["s_1002"];
bookmark2.Range.Text = str16;}
以上是方法的片段代码, 但word在输入的时候打开了,而不是在后台运行,
------解决方案--------------------
object missing = System.Reflection.Missing.Value;
object strfileName = this.MapPath(" "); //你想添加的模版
object readOnly = false;
object isVisible = true;
Word.ApplicationClass oWordApp = new Word.ApplicationClass();
oWordApp.Visible = false;
Word.Document oWordDoc = new Word.DocumentClass();
oWordDoc = oWordApp.Documents.Open(ref strfileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
oWordDoc.Activate();
//操作书签//
object strsave = this.MapPath(" ");//保存路径
oWordDoc.SaveAs(ref strsave, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
oWordDoc.Close(ref missing, ref missing, ref missing);
oWordApp.Quit(ref missing, ref missing, ref missing);
我这么做就可以。你试试。
------解决方案--------------------就把你下面第二行的 = true 改为 = false就搞定
------解决方案--------------------