Gokul Gokul - 3 years ago 93
C# Question

How to delete the visible rows after Auto Filter , excluding the heading row?

In Excel Interop, after setting a

, then I need to delete all visible rows except the first row. Since the first row is the heading row of the sheet.
Thanks .

Answer Source
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download