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.

Fri Sep 27, 2019 6:15 am

Hello,

I have a DOCX document that contains serveral tables.

I need to remove all lines in all tables where in column 3 the text "delete" appears.

I checked this article:
https://www.e-iceblue.com/Tutorials/Spi ... B.NET.html

In this article a fixed linenumber in table 0 is removed.... but I need to search for text "delete" in many tables and remove all lines that contain "delete" in third column

Is it possible to do this ?

Heinz4711
 
Posts: 20
Joined: Thu Feb 07, 2019 5:22 pm

Fri Sep 27, 2019 9:07 am

Hi,

Thanks for your inquiry.
Please refer to the code below.

Code: Select all
            Document doc = new Document();
            doc.LoadFromFile(@"……\filename.docx");

            foreach(Section s in doc.Sections)
            {
                foreach(Table t in s.Tables)
                {
                    for (int i = t.Rows.Count - 1; i >= 0; i--)
                    {
                        //delete all the lines which contain “delete” in the third column.
                        if (t.Rows[i].Cells[2].Paragraphs[0].Text.Contains("delete"))
                        {
                            t.Rows.RemoveAt(i);
                        }
                    }
                }
            }
            doc.SaveToFile(@"reslut.docx",FileFormat.Docx);


If the code couldn't solve your issue, to help us investigate it accurately, please offer us your input Word file and your desired result file. You could upload them here or send us(support@e-iceblue.com) via email.

Best wishes,
Amber
E-iceblue support team
Last edited by Amber.Gu on Fri Nov 01, 2019 2:47 am, edited 1 time in total.
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Wed Oct 30, 2019 3:14 am

Hi,

Greetings from E-iceblue.
Have you tried the code I offered you last time? Does it solve your issue?
Could you please give us some feedback at your convenience?

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Wed Oct 30, 2019 5:04 pm

well, yes... but in my case it was nessessary to loop from the last line to the first line

Heinz4711
 
Posts: 20
Joined: Thu Feb 07, 2019 5:22 pm

Thu Oct 31, 2019 7:04 am

Hi,

Thanks for your feedback.
Any question, welcome to contact us.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Return to Spire.Doc