Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Freeze Panes in multiple worksheets C#

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;
like image 694
Vbp Avatar asked Jan 30 '14 21:01

Vbp


People also ask

How do you freeze columns A and B and rows 1 through 2 in the worksheet in Excel?

Freeze columns and rows Select the cell below the rows and to the right of the columns you want to keep visible when you scroll. Select View > Freeze Panes > Freeze Panes.


1 Answers

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.

like image 91
Vbp Avatar answered Oct 19 '22 04:10

Vbp