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# vba vba

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


I figured it out!

@Jaime's solution to freezing the top row worked perfectly. And the following is my solution to applying the filter:

Thanks,KBP

// Fix first rowworkSheet.Activate();workSheet.Application.ActiveWindow.SplitRow = 1;workSheet.Application.ActiveWindow.FreezePanes = true;// Now apply autofilterExcel.Range firstRow = (Excel.Range)workSheet.Rows[1];firstRow.AutoFilter(1,                     Type.Missing,                     Excel.XlAutoFilterOperator.xlAnd,                     Type.Missing,                     true);


Try this...

workSheet.Activate();workSheet.Application.ActiveWindow.SplitRow = 1;workSheet.Application.ActiveWindow.FreezePanes = true;


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

There could be some System.Reflection.Missing.Value that need to be passed with the arguments, but this was VB.Net code I've converted out of my mind.