0

In Excel Interop, after setting a Range.Autofilter(), then I need to delete all visible rows except the first row. Since the first row is the heading row of the sheet. Thanks .

Gokul
  • 788
  • 2
  • 12
  • 30

1 Answers1

0
Excel.Application objexcel = new Microsoft.Office.Interop.Excel.Application();
Excel.Workbook xlBook = objexcel.Workbooks.Open(filename);
Excel.Worksheet xlSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlBook.Worksheets.get_Item(1);
range = xlSheet.UsedRange;
Excel.Range last =xlSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
range.get_Range("A2", last).Delete(XlDeleteShiftDirection.xlShiftUp);

This worked.

Gokul
  • 788
  • 2
  • 12
  • 30