How to Freeze Top Row and Apply Filter in Excel Automation with C#

How to Freeze Top Row and Apply Filter in Excel Automation with C#

Asked on January 10, 2019 in Excel.
Add Comment


  • 3 Answer(s)

    Use this solution to Freeze Top Row and Apply Filter in Excel Automation with C#

    // Fix first row
    workSheet.Activate();
    workSheet.Application.ActiveWindow.SplitRow = 1;
    workSheet.Application.ActiveWindow.FreezePanes = true;
    // Now apply autofilter
    Excel.Range firstRow = (Excel.Range)workSheet.Rows[1];
    firstRow.AutoFilter(1, 
                        Type.Missing, 
                        Excel.XlAutoFilterOperator.xlAnd, 
                        Type.Missing, 
                        true);
    
    Answered on January 10, 2019.
    Add Comment

    Use this alternative method :

    workSheet.Activate();
    workSheet.Application.ActiveWindow.SplitRow = 1;
    workSheet.Application.ActiveWindow.FreezePanes = true;
    
    Answered on January 10, 2019.
    Add Comment

    Try this code :

    workSheet.EnableAutoFilter = true;
    workSheet.Cells.AutoFilter(1);
     
    //Set the header-row bold
    workSheet.Range["A1", "A1"].EntireRow.Font.Bold = true;
     
    //Adjust all columns
    workSheet.Columns.AutoFit();
    

        The System.Reflection.Missing.Value  need to be passed the argument, this was VB.Net code.

    Answered on January 10, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.