通过互操作打开文档时如何使 word 可见?
我想通过互操作打开一个word文档,并且word必须在该过程中可见。它看起来相当简单,因为在word文档的打开函数中有一个名为“visible”的参数。但是word在后台。什么我失踪了吗?
static void Main(string[] args)
{
Microsoft.Office.Interop.Word.Application word = null;
word = new Microsoft.Office.Interop.Word.Application();
object inputFile = "c:\\test.docx";
object confirmConversions = false;
object readOnly = true;
object visible = true;
object missing = Type.Missing;
// Open the document...
Microsoft.Office.Interop.Word.Document doc = null;
doc = word.Documents.Open(
ref inputFile, ref confirmConversions, ref readOnly, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref visible,
ref missing, ref missing, ref missing, ref missing);
doc.Activate();
Console.ReadKey();
}
I want to open a word document through interop and word must be visible in the process.It looks to be fairly straight forward because there is a parameter called "visible in the open function on a word document. But word is in the background. What am I missing?
static void Main(string[] args)
{
Microsoft.Office.Interop.Word.Application word = null;
word = new Microsoft.Office.Interop.Word.Application();
object inputFile = "c:\\test.docx";
object confirmConversions = false;
object readOnly = true;
object visible = true;
object missing = Type.Missing;
// Open the document...
Microsoft.Office.Interop.Word.Document doc = null;
doc = word.Documents.Open(
ref inputFile, ref confirmConversions, ref readOnly, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref visible,
ref missing, ref missing, ref missing, ref missing);
doc.Activate();
Console.ReadKey();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
唔。显然,应用程序和文档都必须可见。所以解决方案是添加行(在 doc.Activate() 之前):
Hmm. Apparantly both the application and the document has to be visible. So the solution is to add the line (before doc.Activate() ):