Create filter in excel from C # using Interop

1

In the header I want the filter to appear once the document has been created in excel.

I have tried several options and combinations, but NO have worked for me.

Option 1:

oRng = oSheet.get_Range("A1", "J1");
oRng.AutoFilter("1", "<>", Microsoft.Office.Interop.Excel.XlAutoFilterOperator.xlOr, "", true);

Option 2:

oSheet.Application.ActiveWindow.SplitRow = 1;
oSheet.Application.ActiveWindow.FreezePanes = true;
oRng = (Microsoft.Office.Interop.Excel.Range)oSheet.Rows[1];
oRng.AutoFilter(1, Type.Missing, Microsoft.Office.Interop.Excel.XlAutoFilterOperator.xlAnd, Type.Missing, true);

The errors that they give me are the following:

  

1- "The operation could not be completed for the range of cells   selected. Select a single cell within the range and try it   again. "

     

2- "Error in the AutoFilter method of the Range class."

    
asked by Vitaly 27.12.2016 в 12:59
source

1 answer

0

You may want to try the first option, with a range of one cell:

oSheet.get_Range("A1", "A1")
    
answered by 27.12.2016 в 19:18