问题
I´m working on a little commandline tool to extract some data from an excel sheet.
I want to delete all rows which are visible after applying an AutoFilter.
Unfortunately, I just don´t know how to continue. After some searching, I did not find a working answer for me.
Here is what I´ve got so far:
oXL = new Excel.Application();
oXL.Visible = false;
oWB = oXL.Workbooks.Open(source);
oXS = (Excel.Worksheet)oWB.Sheets[1];
Excel.Range filter = oXS.UsedRange;
filter.AutoFilter(8, "<>text to filter");
How do I delete all rows which are shown after filtering?
Thanks.
CRowland
回答1:
Excel.Range filter = XlSheet_1.UsedRange;
filter.AutoFilter(8, "<>text to filter");
filter.Delete(XlDeleteShiftDirection.xlShiftUp);
回答2:
Maybe it's a bit late for an answer but I put it for reference.
Every Excel.Range
object has a Delete()
method:
Excel.Range filter = oXS.UsedRange;
filter.AutoFilter(8, "<>text to filter");
filter.AutoFilter.Range.Delete();
来源:https://stackoverflow.com/questions/34746516/c-sharp-excel-how-to-delete-visible-rows-after-autofilter