简体   繁体   English

无法使用Interop打开Office文档

[英]Can't open Office document with Interop

Code: 码:

ApplicationClass projectApp = new ApplicationClass();

if (projectApp.FileOpen(path, true, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
PjPoolOpen.pjDoNotOpenPool, Missing.Value, Missing.Value, Missing.Value, Missing.Value))
{
    projects = new List<Project>(projectApp.Projects.Cast<Project>());
    foreach (Project project in projects)
    {
        MSProjectProject msProject = new MSProjectProject();

        msProject.Author = project.Author.ToString(); // ERROR HERE
        msProject.Name = project.Name;
    }
}

Exception: 例外:

Unable to cast COM object of type 'Microsoft.Office.Interop.MSProject.ProjectClass' to interface type 'Microsoft.Office.Interop.MSProject._IProjectDoc'. 无法将类型为“ Microsoft.Office.Interop.MSProject.ProjectClass”的COM对象转换为接口类型为“ Microsoft.Office.Interop.MSProject._IProjectDoc”。 This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020B00-0000-0000-C000-000000000046}' failed due to the following error: The RPC server is unavailable. 由于以下错误,此操作失败是因为在COM组件上针对具有IID'{00020B00-0000-0000-C000-000000000046}'的接口的COM组件上的QueryInterface调用由于以下错误而失败:RPC服务器不可用。 (Exception from HRESULT: 0x800706BA). (来自HRESULT的异常:0x800706BA)。

Exception 2: (This one does not get caught by the try block) 例外2 :(此代码不会被try块捕获)

DisconnectedContext was detected 检测到DisconnectedContext

Transition into COM context 0x265048 for this RuntimeCallableWrapper failed with the following error: The requested object does not exist. 为此RuntimeCallableWrapper转换到COM上下文0x265048失败,出现以下错误:请求的对象不存在。 (Exception from HRESULT: 0x80010114). (来自HRESULT的异常:0x80010114)。 This is typically because the COM context 0x265048 where this RuntimeCallableWrapper was created has been disconnected or it is busy doing something else and cannot process the context transition. 这通常是因为创建此RuntimeCallableWrapper的COM上下文0x265048已断开连接,或者它正忙于执行其他操作并且无法处理上下文转换。 No proxy will be used to service the request on the COM component and calls will be made to the COM component directly. 没有代理将用于为COM组件上的请求提供服务,并且将直接对COM组件进行调用。 This may cause corruption or data loss. 这可能会导致损坏或数据丢失。 To avoid this problem, please ensure that all COM contexts/apartments/threads stay alive and are available for context transition, until the application is completely done with the RuntimeCallableWrappers that represents COM components that live inside them. 为避免此问题,请确保所有COM上下文/公寓/线程都保持活动状态并且可用于上下文转换,直到使用代表其中包含COM组件的RuntimeCallableWrappers完全完成应用程序为止。

When I first access the project the exception is thrown. 当我第一次访问该project ,将引发异常。 What am I doing wrong? 我究竟做错了什么?

Also, I'm new to Interop and it bothers me that when I access a file, it opens with office. 另外,我对Interop还是陌生的,当我访问文件时,它会随Office打开而困扰。 Isn't there a way to only peek its content and not open it? 是否没有办法只浏览内容而不打开内容?

Interop Runtime Version: v2.0.50727; 互操作运行时版本: v2.0.50727;

Interop Version: 14.0.0.0; 互操作版本: 14.0.0.0;

Project Version: 2013 (15.0.4569.1504); 项目版本: 2013(15.0.4569.1504);

Resolution is simple: Stop using Interop, it is GARBAGE. 解决方法很简单:停止使用Interop,它是垃圾。 It's messy, takes forever to process documents, opens the documents before it can process it and sometimes will simply not work and not tell you why, except when it does and you have problems like the above, where nobody can help. 这很麻烦,需要花费大量的时间来处理文档,在可以处理文档之前先打开文档,有时根本无法正常工作,也无法告诉您原因,除非是这样做的时候,并且您遇到上述问题,而没人能提供帮助。

Though MPXJ implements Java inside .NET, it's still better than Interop! 尽管MPXJ在.NET内实现Java,但它仍然比Interop更好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Office.Interop.Word.Document.Open引发COMException - Office.Interop.Word.Document.Open throwing COMException MS Office Interop-无法发布对RCW的引用 - MS Office Interop - can't release references to RCW 无法添加对microsoft.office.interop.excel的引用 - Can't add a reference to microsoft.office.interop.excel 无法获得Microsoft.Office.Interop引用的工作 - Can't get Microsoft.Office.Interop reference to work 无法在参考列表中找到Microsoft.Office.Interop.Word - Can't locate Microsoft.Office.Interop.Word in Reference List 无法使用Office.Interop和C#打开受密码保护的Excel文档 - Unable to open password protected Excel document with Office.Interop and C# 如何在 C# 中使用 Microsoft.Office.Interop.Excel.Application 保存打开的文档? - How do you save an open document using Microsoft.Office.Interop.Excel.Application in C#? 如何使用 Microsoft Office Word Interop 与复制+粘贴的表格进行交互? 粘贴的表格不会添加到 document.Tables.count - How can you interact with a copied+pasted Table using Microsoft Office Word Interop? Pasted table doesn't add to document.Tables.count 我不能在iis7开办公室 - i can't open office in iis7 打开Outlook时,Microsoft.Office.Interop.Outlook确认电子邮件不起作用 - Microsoft.Office.Interop.Outlook Confirmation email doesn't work when Outlook is open
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM