deleting rows from an excel file using c#

后端 未结 2 821
一向
一向 2020-12-11 06:46

I am opening an excel file like this:

Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;

string str;
int rC         


        
2条回答
  •  Happy的楠姐
    2020-12-11 07:28

    Once you have a reference to the worksheet say

    for(int i = 1; i <=100; i++)
    {
      if(!worksheet.Cells[i,1].Contains("SomeString"))
      {
         ((Range)worksheet.Rows[i]).Delete(shiftDirection)
      }
    }
    

    where shiftDirection see here: Range.Delete method

    You may have to cast the Cell's content to a string.

提交回复
热议问题