Zu Lesen versucht, ein MS-Office Dokument

Ich habe ein Stück code, dass ich mit Lesen MS-Office-Word-Dokumente.

static void ReadMSOfficeWordFile(string file) {
    try {
        Microsoft.Office.Interop.Word.Application msWordApp = new Microsoft.Office.Interop.Word.Application();
        object nullobj = System.Reflection.Missing.Value;
        object ofalse = false;
        object ofile = file;

        Microsoft.Office.Interop.Word.Document doc = msWordApp.Documents.Open(
                                                    ref ofile, ref nullobj, ref nullobj,
                                                    ref nullobj, ref nullobj, ref nullobj,
                                                    ref nullobj, ref nullobj, ref nullobj,
                                                    ref nullobj, ref nullobj, ref nullobj,
                                                    ref nullobj, ref nullobj, ref nullobj,
                                                    ref nullobj);
        string result = doc.Content.Text.Trim();
        doc.Close(ref ofalse, ref nullobj, ref nullobj);
        msWordApp.Quit();
        CheckLineMatch(file, result);
    }
    catch {
        RaiseError("Unable to parse file because of MS Office error.", file);
    }
}

Habe ich drei Probleme mit diesem.

Ersten - Sie setzt auf MS-Office wird auf jedem system installiert, könnte dies weiter ausführen. Einige Leute bevorzugen Libre Office, aber dies muss noch um gegen MS Office Word-Dokumente.

Zweitens - ich weiß nicht, ob dies auch Arbeit für MS Office 2003 UND MS Office 2007-Dokumente...

Dritte - Es ist LANGSAM. Es ist unerträglich langsam.

SO! Ich nehme an, es MUSS einen besseren Weg, als diese. Ich vermute, dass jemand einen besseren Weg kennen, als das, was ein Anfänger kommt mit. Ich versuche nur, um Lesen Sie den text im Dokument, sonst nichts.

InformationsquelleAutor MTeck | 2012-03-12
Schreibe einen Kommentar