I\'ve been working a lot with EPPlus to generate Excel files for the number of exports that my project requires me to do. Most of the exports that they want tend to match up per
It turns out that EPPlus has a built-in function for doing that on the Worksheet
object itself called FreezePanes
. This function has 2 parameters, both of which are int
: Row and Column. Doing this will freeze whatever rows or columns you wish to have locked in place while viewing the worksheet.
One of the examples on the EPPlus website uses it, although it's not the main focus of the example/ That example can be found here.
There is one gotcha with this function that you should know about, though: The number that you use for the row or column parameter is actually the first column that is NOT frozen in place. In other words, if you want the first 5 columns to be frozen you would have to make the following call:
ws.View.FreezePanes(1,6)
(Where 6 is the first column that is not frozen)
I realized that when using @IronMan84's suggestion, if you're only interested in the row but not the column. You can use
ws.View.FreezePanes(3, 1); // (Freeze Row 2 and no column)