Hi ravikumar-1532,
You can also try to delete by looping through each row.
Here is my test code example:(The data is located in column A starting A1)
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
long i;
i = 1L;
Microsoft.Office.Interop.Excel.Workbook ThisWorkbook = excel.Workbooks.Open(@"C:\Users\Desktop\t1.xls");
while (i <= ThisWorkbook.ActiveSheet.Range("A1").CurrentRegion.Rows.Count)
{
short number;
bool result = Int16.TryParse(ThisWorkbook.ActiveSheet.Cells(i, 1).Text, out number);
if (number ==1)
{
Console.WriteLine(ThisWorkbook.ActiveSheet.Cells(i, 1).Text);
ThisWorkbook.ActiveSheet.Cells(i, 1).EntireRow.Delete();
}
else
{
i = i + 1L;
}
}
ThisWorkbook.SaveAs(@"C:\Users\Desktop\t2.xls");
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.