Files
ClosedXML/ClosedXML_Examples/Columns/InsertColumns.cs
T
Thom Lamb 2cd6df6481 Initial commit of the ClosedXML library
Establishes the foundational structure, core Excel functionality, and tooling.

- Implements base components for cells, ranges, columns, and rows.
- Integrates a custom calculation engine with a wide range of Excel functions.
- Adds comprehensive support for styling, conditional formatting, data validation, comments, pictures, and charts.
- Configures build setup, project metadata (NuGet), and developer guidelines.
- Includes editor and Git attributes for consistent code style and line endings.
2026-06-23 11:02:53 -05:00

41 lines
1.3 KiB
C#

using ClosedXML.Excel;
using System;
using System.Linq;
namespace ClosedXML_Examples.Columns
{
public class InsertColumns : IXLExample
{
public void Create(String filePath)
{
var workbook = new XLWorkbook();
var ws = workbook.Worksheets.Add("Inserting Columns");
// Color the entire spreadsheet using columns
ws.Columns().Style.Fill.BackgroundColor = XLColor.LightCyan;
// Put a value in a few cells
foreach (var r in Enumerable.Range(1, 5))
foreach (var c in Enumerable.Range(1, 5))
ws.Cell(r, c).Value = "X";
var blueColumn = ws.Column(2);
var redColumn = ws.Column(5);
blueColumn.Style.Fill.BackgroundColor = XLColor.Blue;
blueColumn.InsertColumnsAfter(2);
redColumn.Style.Fill.BackgroundColor = XLColor.Red;
redColumn.InsertColumnsBefore(2);
ws.Rows(3, 4).Style.Fill.BackgroundColor = XLColor.Orange;
ws.Range("B1:D1").InsertColumnsAfter(2);
ws.Range("B2:D2").InsertColumnsBefore(2);
ws.Range("B3:D3").InsertColumnsAfter(2);
ws.Range("B4:D4").InsertColumnsBefore(2);
workbook.SaveAs(filePath);
}
}
}