Charan Gourishetty Charan Gourishetty - 7 months ago 34
C# Question

How to read tables from a particular place in a document?

When I use the below line It reads all tables of that particular document:

foreach (Microsoft.Office.Interop.Word.Table tableContent in document.Tables)

But I want to read tables of a particular content for example from one identifier to another identifier.

Identifier can be in the form of [SRS oraganisation_123] to another identifier [SRS Oraganisation_456]

I want to read the tables only in between the above mentioned identifiers.

Suppose 34th page contains my identifier so I want read all tables from that point to until I come across my second identifier. I don't want to read remaining tables.

Please ask me for any clarification in the question.


Say start and end Identifiers are stored in variables called myStartIdentifier and myEndIdentifier -

    Range myRange = doc.Range();
    int iTagStartIdx = 0;
    int iTagEndIdx = 0;

    if (myRange.Find.Execute(myStartIdentifier))
        iTagStartIdx = myRange.Start;

    myRange = doc.Range();    
    if (myRange.Find.Execute(myEndIdentifier))
        iTagEndIdx = myRange.Start;

    foreach (Table tbl in doc.Range(iTagStartIdx,iTagEndIdx).Tables)
       // Your code goes here