Freeze Panes in multiple worksheets C#

c#, excel, excel-interop, office-interop, winforms

Solution

I Hope it help others. I have used ClosedXML Library for Excel and after creating each worksheet I used

worksheet.SheetView.Freeze(1,6);  

This freezes the Row 1, Col 6. You can freeze any row/column. Here is link to ClosedXML. It's widely supported and very good documentation.

Problem

I am working on MS Excel 2013 generating report where all the worksheets in workbook should have freeze pane at column 6 and row 1. I have searched on Google but could not find any solution as for freezing the pane, workbook has to be active. I have tried a lot of things but no success. I will really appreciate if someone can help me. ``` Excel.Application excel = new Excel.Application(); Excel.Workbook workbook = excel.Workbooks.Open("filelocation"); foreach (Excel.Worksheet ws in workbook.Worksheets) { ws.Application.ActiveWindow.SplitColumn = 6; ws.Application.ActiveWindow.SplitRow = 1; ws.Application.ActiveWindow.FreezePanes = true; } excel.Visible = true; ```

Original source