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

时间:2010-06-04 15:44:15

标签: c# asp.net com openoffice-writer

我在ASP .NET应用程序中使用Open Office API从* .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行出现错误。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

快速猜测:您之前运行应用程序的用户之前从未打开过OpenOffice。尝试以该用户身份登录并运行OpenOffice它会询问几个问题,然后关闭OpenOffice并注销。然后尝试再次运行您的应用....