The first poster is here :). I had the following problem: Excel 2010 automation from a WinForms C # application. My test pattern is as follows:
Index Value1 Value2 AAA 2 3 AAA 3 4 AAA 3 8 BBB 2 2 BBB 5 6 BBB 3 5 CCC 1 2 CCC 2 2 DDD 2 5
I successfully open a book and load a sheet from my C # application. After that, I run the following code:
Excel.Range range = xlSheet.UsedRange; range.AutoFilter(1, "AAA", Excel.XlAutoFilterOperator.xlAnd, Type.Missing, true); Excel.Range filteredRange = range.SpecialCells(Excel.XlCellType.xlCellTypeVisible);
This works as expected, and filterRange now contains the first four rows of my test pattern (column names and all rows are βAAAβ). If, however, I try to use AutoFilter to get all the "BBB" strings, for example,
range.AutoFilter(1, "BBB", Excel.XlAutoFilterOperator.xlAnd, Type.Missing, true); Excel.Range filteredRange = range.SpecialCells(Excel.XlCellType.xlCellTypeVisible);
Ultimately, I get only the first row of the table (column names) in the filterRange range. If I really open the table in Excel, I see that it is being correctly filtered (the "BBB" rows) are being filtered, but somehow the Range.SpecialCells () method does not behave as expected and returns only the first row. I tried everything I could think of, but since I'm new to Excel automation, I might have missed something, so I thought you guys could help. The only thing that comes to my mind is that in the first case ("AAA"), all visible rows are consecutive - the column names are on row 1, and the rows "AAA" are 2, 3, and 4, respectively. In the second case, the names are indicated on line 1, but the lines "BBB" have an index of 5, 6 and 7, that is, there is a "hole" in the table. Could this affect the SpecialCells () method?
Thanks in advance for any input you have.