C# - Excel - How to delete visible rows after AutoFilter?

十年热恋 提交于 2021-01-29 18:00:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!