Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save openize-com-gists/99a3cf5c7a85da893b3daa67f192ffbd to your computer and use it in GitHub Desktop.
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.
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