C# 在ASP.NET中使用Open Office API时出错

C# 在ASP.NET中使用Open Office API时出错,c#,asp.net,com,openoffice-writer,C#,Asp.net,Com,Openoffice Writer,我在ASP.NET应用程序中使用OpenOfficeAPI从*.doc文件中读取文本内容 public static bool getTextV2(string siteURL, string[] search) { //Create a new ServiceManager Type object Type tServiceManager = Type.GetTypeFromProgID("com.sun.star.ServiceManager", true); //C

我在ASP.NET应用程序中使用OpenOfficeAPI从*.doc文件中读取文本内容

public static bool getTextV2(string siteURL, string[] search)
{
    //Create a new ServiceManager Type object
    Type tServiceManager = Type.GetTypeFromProgID("com.sun.star.ServiceManager", true);
    //Create a new ServiceManager Com object using our
    //ServiceManager type object
    object oServiceManager = System.Activator.CreateInstance(tServiceManager);
    //Create our Desktop Com object
    object oDesktop = Invoke(oServiceManager, "createinstance",
    BindingFlags.InvokeMethod,
    "com.sun.star.frame.Desktop");
    //Create an array for our load parameter
    Object[] arg = new Object[4];
    arg[0] = siteURL;
    arg[1] = "_blank";
    arg[2] = 0;
    arg[3] = new Object[] { };
    //Create our new blank document
    object oComponent = Invoke(oDesktop,
    "loadComponentFromUrl",
    BindingFlags.InvokeMethod,
    arg
    );
    //Create an empty array for the getText method
    arg = new Object[0];
    //Get our Text Com object
    Object oText = Invoke(oComponent,
    "getText",
    BindingFlags.InvokeMethod,
    arg
    );
    Object Text = Invoke(oText,
    "getString",
    BindingFlags.InvokeMethod,
    arg
    );
    string content = Text.ToString();
    content = content.ToLower();
    bool flag = true;
    foreach (string current in search)
    {
        if (!content.Contains(current)) flag = false;
    }
    arg = new Object[0];
    Invoke(oComponent,
    "dispose",
    BindingFlags.InvokeMethod,
    arg
    );

    return flag;
}
public static object Invoke(object obj, string method, BindingFlags binding, params object[] par)
{
    return obj.GetType().InvokeMember(method, binding, null, obj, par);
}
但我有以下错误:

Retrieving the COM class factory for component with CLSID {82154420-0FBF-11D4-8313-005004526AB4} failed due to the following error: 80080005.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {82154420-0FBF-11D4-8313-005004526AB4} failed due to the following error: 80080005.
源错误:

Line 56: //Create a new ServiceManager Com object using our
Line 57: //ServiceManager type object
Line 58: object oServiceManager = System.Activator.CreateInstance(tServiceManager);
Line 59: //Create our Desktop Com object
Line 60: object oDesktop = Invoke(oServiceManager, "createinstance",
因此,第58行有一个错误


有什么想法吗?

快速猜测:可能是您运行应用程序的用户以前从未打开过OpenOffice。尝试以该用户身份登录并运行OpenOffice,它将询问一些问题,然后关闭OpenOffice并注销。然后再次尝试运行应用程序……

我不确定OO.o对于文本提取是否非常有效。您可能会对一篇关于使用内置索引服务从MS Word文档中提取文本的文章感兴趣:我使用OpenOffice构建了文档到html转换的解决方案,速度非常快。