2016-11-22 10 views
0

は、私は次の構造を持っていると仮定した後、テーブルのインデックスを取得します - 私は「paragraph3の1.3見出し」の後の第2のテーブルのインデックスを取得したいC#が:特定の段落

enter image description here

を、次のことを意味します。 -

入力は

1.3 paragraph3の見出しである

期待出力

は、この文書で説明するテーブルであるか、

The requested member of the collection equlas 4と言うことができます。次のコード

Microsoft.Office.Interop.Word.Application app = new  Microsoft.Office.Interop.Word.Application(); 
Documents docs = app.Documents; 
Document doc = docs.Open(sDocPath, ReadOnly: true); 
Table t = doc.Tables[4] // 4 that what I need 

答えて

0

を使用するためにあなたはVB.NETに以下のコードを試みることができる、あるいは単にC#のに変換この

ターゲット。

<TestMethod()> Public Sub getDocText() 
    Dim filepath As String = "C:\Test Table.docx" 
    If File.Exists(filepath) AndAlso (Path.GetExtension(filepath).ToUpper.Equals(".DOCX") Or Path.GetExtension(filepath).ToUpper.Equals(".DOC")) Then 
    Dim app As Word.Application = New Word.Application 
    Dim doc As Word.Document = app.Documents.Open(filepath) 
    Dim topic1Range As Word.Range = doc.Content 
    Dim topic2Range As Word.Range = doc.Content 
    Dim Find As Word.Find = topic1Range.Find() 
    Find.Execute("1.2 The headline of paragraph3") 

    Dim Find2 As Word.Find = topic2Range.Find() 
    Find2.Execute("1.3 The headline of paragraph3") 

    Dim contentRange As Word.Range = doc.Range(topic1Range.End, topic2Range.Start) 
    MsgBox(contentRange.Tables.Count) 
    app.Quit() 
    End If 
End Sub 
関連する問題