How to select a part of a table in Word document with C#? (VSTO)

Sh Ghiassi 21 Reputation points
2021-03-02T15:49:51.82+00:00

I have a table in Word document. I want to able to select a row or column or only a cell or whole table to modify. now I can select the complete table and modify all cells, but I can not select a single row or column or cell. I can not create a range for this purpose.

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,399 questions
Word Management
Word Management
Word: A family of Microsoft word processing software products for creating web, email, and print documents.Management: The act or process of organizing, handling, directing or controlling something.
887 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. David 146 Reputation points
    2021-11-10T05:51:13.63+00:00

    Install Spire.Doc in your Visual Studio via NuGet, and you'll be able to access a specific row and a specific cell using the following code.

    using Spire.Doc;
    
    namespace AccessToTable
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Create a Document object 
                Document doc = new Document();
                //Load the Word document that contains tables
                doc.LoadFromFile(@"‪C:\Users\Administrator\Desktop\table.docx");
                //Get the first section
                Section section = doc.Sections[0];
                //Get the first table from the section
                Table table = section.Tables[0] as Table;
                //Get the first row by its index
                TableRow row = table.Rows[0];
                //Get the first cell by its index
                TableCell cell = row.Cells[0];
            }
        }
    }
    
    0 comments No comments