Created
May 28, 2025 05:48
-
-
Save openize-com-gists/99a3cf5c7a85da893b3daa67f192ffbd to your computer and use it in GitHub Desktop.
This example demonstrate, how to freeze a column in excel using C# open source library.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Openize.Cells; | |
class Program | |
{ | |
static void Main() | |
{ | |
// Create a new workbook | |
using (var workbook = new Workbook()) | |
{ | |
// Get the first worksheet | |
var worksheet = workbook.Worksheets[0]; | |
// Add some sample data | |
worksheet.Cells["A1"].PutValue("Employee ID"); | |
worksheet.Cells["B1"].PutValue("First Name"); | |
worksheet.Cells["C1"].PutValue("Last Name"); | |
worksheet.Cells["D1"].PutValue("Department"); | |
worksheet.Cells["E1"].PutValue("Salary"); | |
// Add sample employee data | |
for (int i = 2; i <= 10; i++) | |
{ | |
worksheet.Cells[$"A{i}"].PutValue($"EMP{i:000}"); | |
worksheet.Cells[$"B{i}"].PutValue($"FirstName{i}"); | |
worksheet.Cells[$"C{i}"].PutValue($"LastName{i}"); | |
worksheet.Cells[$"D{i}"].PutValue($"Department{i % 3 + 1}"); | |
worksheet.Cells[$"E{i}"].PutValue(50000 + (i * 1000)); | |
} | |
// Freeze the first column | |
worksheet.FreezePane(0, 1); | |
// Save the workbook | |
workbook.Save("FrozenColumn_Example.xlsx"); | |
Console.WriteLine("Excel file created with frozen first column!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment