Parse-Tabelle mit Microsoft.Office.Interop.Word, nur-text aus der ersten Spalte?

Arbeite ich auf ein Programm schreiben, das analysieren von text-Daten aus einem Microsoft Word 2010-Dokument. Speziell möchte ich, um text aus jeder Zelle in der ersten Spalte jeder Tabelle in das Dokument.

Referenz, das Dokument sieht gerne dies:
Parse-Tabelle mit Microsoft.Office.Interop.Word, nur-text aus der ersten Spalte?

Nur muss ich den text aus den Zellen in der ersten Spalte auf jeder Seite. Ich werde diesen text in eine interne datatable.

Mein code bisher sieht so aus:

private void button1_Click(object sender, EventArgs e)
    {
        //Create an instance of the Open File Dialog Box
        var openFileDialog1 = new OpenFileDialog();

        //Set filter options and filter index
        openFileDialog1.Filter = "Word Documents (.docx)|*.docx|All files (*.*)|*.*";
        openFileDialog1.FilterIndex = 1;
        openFileDialog1.Multiselect = false;

        //Call the ShowDialog method to show the dialog box.
        openFileDialog1.ShowDialog();
        txtDocument.Text = openFileDialog1.FileName;

        var word = new Microsoft.Office.Interop.Word.Application();
        object miss = System.Reflection.Missing.Value;
        object path = openFileDialog1.FileName;
        object readOnly = true;
        var docs = word.Documents.Open(ref path, ref miss, ref readOnly, 
                                       ref miss, ref miss, ref miss, ref miss, 
                                       ref miss, ref miss, ref miss, ref miss, 
                                       ref miss, ref miss, ref miss, ref miss, 
                                       ref miss);

        //Datatable to store text from Word doc
        var dt = new System.Data.DataTable();
        dt.Columns.Add("Text");

        //Loop through each table in the document, 
        //grab only text from cells in the first column
        //in each table.
        foreach (Table tb in docs.Tables)
        {
            //insert code here to get text from cells in first column
            //and insert into datatable.
        }

        ((_Document)docs).Close();
        ((_Application)word).Quit();
    }

Ich bin stecken in dem Teil, wo ich schnappe mir den text aus jeder Zelle und fügen Sie es auf meine datatable. Kann jemand mir einige Hinweise? Ich würde Sie sicher zu schätzen.

Dank!

InformationsquelleAutor Kevin | 2013-07-22
Schreibe einen Kommentar