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

前端 未结 5 1320
轮回少年
轮回少年 2021-02-02 06:24

I have automation to create an Excel document from C#. I am trying to freeze the top row of my worksheet and apply filter. This is the same as in Excel 2010 if you select View >

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-02 06:48

    The below solutions are working fine, but it is freezing the first row of the current visible snapshot of the sheet. For ex: If your current sheet visible snapshot is from row 43 to some number say 90.. then freeze row is getting applied to 43.

    If you want only the very first row of sheet (heading row) to be frozen, no matter the excel scroll position, then the below solution worked for me. This code scrolls up the excel sheet to row 1. You have to store the position if you want to go back to the previous position before freeze.

    worksheet.Application.ActiveWindow.ScrollRow = 1;
    worksheet.Application.ActiveWindow.SplitRow = 1;
    worksheet.Application.ActiveWindow.FreezePanes = true; 
    

提交回复
热议问题