0

我在我的 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 行有一个错误。

有任何想法吗?

4

1 回答 1

1

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

于 2010-10-21T16:28:46.490 回答