错误:命令不可用,因为没有文档是打开的 [英] Error:Command not available because no document is Open

查看:92
本文介绍了错误:命令不可用,因为没有文档是打开的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要使用以下代码使用winwordcontrol对象打开word文档文件。

我正在使用Windows窗体应用程序。





代码:

使用(WordprocessingDocument OpenDoc = WordprocessingDocument.Open(openFileDialog1.FileName,false))

{

winwordcontrolname.LoadDocument(openFileDialog1.FileName); //这里错误

}



我收到错误命令不可用,因为没有文档打开。





请给我一个解决方案!

Hi,
I need to open a word document file using winwordcontrol object using the following code.
I am working on windows form application.


code:
using (WordprocessingDocument OpenDoc = WordprocessingDocument.Open(openFileDialog1.FileName, false))
{
winwordcontrolname.LoadDocument(openFileDialog1.FileName);//error here
}

I am getting an error "Command not available because no document is Open".


Please provide me a solution!

推荐答案

看看你在做什么。您已使用块将文档的新实例作为的目标。你知道在那个上下文中使用做什么吗?



当执行离开using块时,文件是Disposed自动!是的,不再有任何Word文档打开。如果您希望文档保持打开状态,则不能将其用作使用块的目标。
Look at what you're doing. You've put the new instance of the document as the target of a using block. Do you know what using does in that context??

When execution leaves the using block the document is Disposed automatically! Yes, there's is no longer any Word document open. If you want the document to stay open, you cannot use it as the target of a using block.


这篇关于错误:命令不可用,因为没有文档是打开的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆