Word 2007 文档中的 InsertFile 操作抛出“命令失败”;例外

发布于 2024-09-03 02:48:53 字数 511 浏览 2 评论 0原文

当我使用以下代码将一个 Word 2007 文档中的内容插入到另一个使用 C# 中的书签的文档时,出现“命令失败”异常:

string filePath = @“C:\temp\one.doc”;  
object trueObj = true;  
object falseObj = false;  
wordApp.Selection.InsertFile( filePath, ref missing, ref falseObj, ref trueObj, ref falseObj );

“one.doc”是另一个包含表格内容的 Word 文档。

错误代码:-2146824090。当目标对象被处置或不可用时,通常会出现此错误。不知道为什么我会在这里得到它。

此外,当我从目标文档中删除表格内容并仅添加格式化文本时,操作会成功。当通过word GUI进行相同的操作时,操作效果良好。已在互联网上搜索有关此问题的指示,但没有一个对解决此问题有帮助。

预先感谢,
巴拉特·K.

I get the “Command Failed” exception when using the following code to insert content from one word 2007 document into another using bookmarks in c# :

string filePath = @“C:\temp\one.doc”;  
object trueObj = true;  
object falseObj = false;  
wordApp.Selection.InsertFile( filePath, ref missing, ref falseObj, ref trueObj, ref falseObj );

"one.doc" is another word document containing table content.

Error code: -2146824090. This error generally comes when the target object is disposed or unavailable. Not sure why I am getting it here.

Also when I remove table content from the target document and I just add formatted text, the operation succeeds. When the same operation is performed through word GUI, the operation works fine. Have scoured the internet for pointers on this issue, but none were helpful in resolving this.

Thanks in advance,
Bharath K.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

携余温的黄昏 2024-09-10 02:48:53

我们通过定义一个执行上述操作的宏并使用我的程序中的 c# 调用该宏解决了这个问题。成功了!

We have solved this problem by defining a macro that performs the above actions and invoking the macro using c# from my program. That worked!

静水深流 2024-09-10 02:48:53

我遇到了这个问题,我注意到插入文件的范围包含一些锁定的内容控件。在使用 InsertFile 命令之前,请确保范围(此处为选择)不包含锁定的内容控件。
问候。

I encountered this problem and I noticed that range where to insert the file contains some locked content controls. Before using InsertFile command make sure that range (Selection here) does not contain locked content controls.
Regards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文