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

0 votes
I have automated Excel document creation using C#. I'm attempting to apply a filter while also freezing the worksheet's top row. If you choose View > Freeze Panes > Freeze top row, followed by top row Data > Filter, this is the same as in Excel 2010. I have no idea how to use the filter, but I tried the following to freeze the top row, and it simply frozen the entire worksheet. I'm looking for a solution to my issue. I need additional assistance with the data filter issue; if you know of a solution, kindly let me know.
Oct 21, 2022 in Others by Kithuzzz
• 38,000 points
2,661 views

1 answer to this question.

0 votes

Try this:

// 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 Oct 22, 2022 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
0 answers

Data Driven Framework -- how to read and write in excel sheet using Selenium WebDriver with java

I'm using this code to read something, ...READ MORE

Oct 31, 2022 in Others by Kithuzzz
• 38,000 points
660 views
0 votes
1 answer

How do I get an Excel range using row and column numbers in VSTO / C#?

Use: int countRows = xlWorkSheetData.UsedRange.Rows.Count; int countColumns = xlWorkSheetData.UsedRange.Columns.Count; object[,] ...READ MORE

answered Nov 17, 2022 in Others by narikkadan
• 63,600 points
1,773 views
0 votes
1 answer

How to insert a new row in the specified cell only, of Excel sheet using c#?

I have this worksheet with a matrix ...READ MORE

answered Nov 24, 2022 in Others by narikkadan
• 63,600 points
2,351 views
0 votes
1 answer

Generate a flat list of all excel cell formulas

Hello, you'll have to follow certain steps ...READ MORE

answered Feb 18, 2022 in Others by gaurav
• 23,260 points
562 views
0 votes
0 answers

Format an Excel column (or cell) as Text in C#?

When I copy values from a data ...READ MORE

Oct 31, 2022 in Others by Kithuzzz
• 38,000 points
1,034 views
0 votes
1 answer

Microsoft.Office.Interop.Excel for Office 2007

Each client must install the  2007 Microsoft ...READ MORE

answered Nov 5, 2022 in Others by narikkadan
• 63,600 points
1,568 views
0 votes
1 answer

Obtaining Excel worksheet reference by worksheet name via C#

Instead of using Excel.Workbook.Sheets collection, it's easier to access Excel.Workbook.Worksheet collection, ...READ MORE

answered Nov 10, 2022 in Others by narikkadan
• 63,600 points
592 views
0 votes
1 answer

How to freeze the top row and the first column using XlsxWriter?

You can use worksheet.freeze_panes() to achieve this . There ...READ MORE

answered Oct 11, 2022 in Others by narikkadan
• 63,600 points
2,333 views
0 votes
1 answer

How to use data validation and 'no filter' in excel

eventually succeeded in resolving this. Effectively, Filter() ...READ MORE

answered Nov 4, 2022 in Others by narikkadan
• 63,600 points
622 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP