Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Mar 17, 2020 4:42 am

I would like to delete all the rows where a specific string is found in any column of a row. But i am not sure how can this be done.

Thank you.

vengsie94
 
Posts: 1
Joined: Mon Mar 16, 2020 9:50 am

Tue Mar 17, 2020 6:11 am

Hello,

Thanks for your inquiry.
Below is the corresponding code in C# for reference. If there is any question, please provide your input file as well as your desired output, then we will further look into it.
Code: Select all
            Workbook wb = new Workbook();
            wb.LoadFromFile("test.xlsx");
            Worksheet sheet = wb.Worksheets[0];
            //Find cells with the specific string
            CellRange[] textRanges = sheet.FindAllString("E-iceblue", false, false);
            //Get the row index
            List<int> rowIndex = new List<int>();
            foreach(CellRange range in textRanges){
                if (!rowIndex.Contains(range.Row))
                {
                    rowIndex.Add(range.Row);
                }               
            }
            //Delete the corresponding rows
            for (int i = 0; i < rowIndex.Count; i++ )
            {
                sheet.DeleteRow(rowIndex[i] - i);
            }
            wb.SaveToFile("result.xlsx", FileFormat.Version2013);


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Fri Mar 20, 2020 9:13 am

Hello,

Hope you are doing well.
Did you test my code? Could you please give us some feedback at your convenience?
Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.XLS