AutoFilter and Freezing Panes using C# for Excel

  • Thread starter Thread starter rmurthy
  • Start date Start date
R

rmurthy

Help needed please for Auto Filter and Freezing Panes using C# fo
Excel.

Thank
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top