Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sun Aug 08, 2021 5:23 pm

I have word document with dynamic generated tables. I want to get a specific table based on specific column name it has. as i want to create rows for that particular table instead of other tables in document.

kushalzamk
 
Posts: 1
Joined: Sun Aug 08, 2021 5:07 pm

Mon Aug 09, 2021 3:04 am

Hello,

Thanks for your inquiry.
Please refer to the following code to meet your requirement.
Code: Select all
            Document doc = new Document();
            doc.LoadFromFile(@"test.docx");
            foreach (Section sec in doc.Sections)
            {
                foreach (ITable table in sec.Tables)
                {
                    TableRow tableHeader = table.Rows[0];
                    foreach (TableCell headerCell in tableHeader.Cells)
                    {
                        foreach (DocumentObject documentObject in headerCell.ChildObjects)
                        {
                            if (documentObject is Paragraph)
                            {
                                Paragraph paragraph = documentObject as Paragraph;
                                if (paragraph.Text.Equals("the specific column name"))
                                {
                                    table.AddRow();
                                }
                            }
                        }
                    }
                }
            }
            doc.SaveToFile("result.docx", FileFormat.Docx);

If this is not what you want, please provide your input file and your desired output for further investigation. You can send them to us ([email protected]) via email, thanks in advance.


Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Tue Aug 31, 2021 10:40 am

Hello,

Greetings from E-iceblue!
Did the code we provided work for you? Any feedback will be greatly appreciated.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.Doc

cron