Having finally suceeded with getting auto filter in c# to work
wondering if anyone else still wants to know ?
I am posting the code here so to help others as this has been rather
annoying. I got it to work and then the autofilter showed but didn't
drop down, finally worked out the problem.
Anyway to set autofilter in excel from c#
Assuming you alread have an Excel._WorkSheet object then you can
simply do the following:
First get a range object -
Excel.Range oRng = _oSheet.get_Range("a2", "a2");
Next apply the autofilter
oRng.AutoFilter(1, Type.Missing, Excel.XlAutoFilterOperator.xlAnd,
Type.Missing, true);
The above code is the same as going into excel and switching
autofilter on. Doesn't apply any filtering just activates it in the
worksheet. (Don't forget to save your worksheet though...)
I think the parameters of autofilter work as follows:
oRng.AutoFilter(cell, condition 1, operator, Condition 2, show drop
down in this cell)
cell is a numeric value indicating which cell in the range you are
affecting where A = 1 etc. This is the same as selecting custom option
from a drop down auto filter list in excel.
Condition 1 : This is the Action part of the custom filter (i.e
equals, not equals etc - get settings from excel)
Operator is from the Excel.XlAutoFilterOperator enumeration.
Condition 2 is the value that you want to filter on.
The last parameter decides if you want to show the drop down
autofilter in this column (true or false).
i.e if you wish to filter a column called Name (cell A) where the
value equals 'Craig' you would set the autofilter as follows:
oRng.AutoFilter(1, 'equals', Excel.XlAutoFilterOperator.xlAnd,
'Craig', true).
Anyway guys help this helps others as it's been a pain in the
butt.....
If anyone wants more help with this or how to start excel I'll see
what I can do.