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.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using ClosedXML.Excel;
|
||||
|
||||
|
||||
namespace ClosedXML_Examples
|
||||
{
|
||||
public class ColumnCells : IXLExample
|
||||
{
|
||||
|
||||
public void Create(String filePath)
|
||||
{
|
||||
var workbook = new XLWorkbook();
|
||||
var ws = workbook.Worksheets.Add("Column Cells");
|
||||
|
||||
var columnFromWorksheet = ws.Column(1);
|
||||
columnFromWorksheet.Cell(1).Style.Fill.BackgroundColor = XLColor.Red;
|
||||
columnFromWorksheet.Cells("2").Style.Fill.BackgroundColor = XLColor.Blue;
|
||||
columnFromWorksheet.Cells("3,5:6").Style.Fill.BackgroundColor = XLColor.Red;
|
||||
columnFromWorksheet.Cells(8, 9).Style.Fill.BackgroundColor = XLColor.Blue;
|
||||
|
||||
var columnFromRange = ws.Range("B1:B9").FirstColumn();
|
||||
|
||||
columnFromRange.Cell(1).Style.Fill.BackgroundColor = XLColor.Red;
|
||||
columnFromRange.Cells("2").Style.Fill.BackgroundColor = XLColor.Blue;
|
||||
columnFromRange.Cells("3,5:6").Style.Fill.BackgroundColor = XLColor.Red;
|
||||
columnFromRange.Cells(8, 9).Style.Fill.BackgroundColor = XLColor.Blue;
|
||||
|
||||
workbook.SaveAs(filePath);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using ClosedXML.Excel;
|
||||
|
||||
|
||||
namespace ClosedXML_Examples.Columns
|
||||
{
|
||||
public class ColumnCollection : IXLExample
|
||||
{
|
||||
#region Variables
|
||||
|
||||
// Public
|
||||
|
||||
// Private
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
// Public
|
||||
|
||||
// Private
|
||||
|
||||
// Override
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Events
|
||||
|
||||
// Public
|
||||
|
||||
// Private
|
||||
|
||||
// Override
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
// Public
|
||||
public void Create(String filePath)
|
||||
{
|
||||
var workbook = new XLWorkbook();
|
||||
var ws = workbook.Worksheets.Add("Columns of a Range");
|
||||
|
||||
// All columns in a range
|
||||
ws.Range("A1:B2").Columns().Style.Fill.BackgroundColor = XLColor.DimGray;
|
||||
|
||||
var bigRange = ws.Range("A4:V6");
|
||||
|
||||
// Contiguous columns by number
|
||||
bigRange.Columns(1, 2).Style.Fill.BackgroundColor = XLColor.Red;
|
||||
|
||||
// Contiguous columns by letter
|
||||
bigRange.Columns("D", "E").Style.Fill.BackgroundColor = XLColor.Blue;
|
||||
|
||||
// Contiguous columns by letter
|
||||
bigRange.Columns("G:H").Style.Fill.BackgroundColor = XLColor.DeepPink;
|
||||
|
||||
// Spread columns by number
|
||||
bigRange.Columns("10:11,13:14").Style.Fill.BackgroundColor = XLColor.Orange;
|
||||
|
||||
// Spread columns by letter
|
||||
bigRange.Columns("P:Q,S:T").Style.Fill.BackgroundColor = XLColor.Turquoise;
|
||||
|
||||
// Use a single number/letter
|
||||
bigRange.Columns("V").Style.Fill.BackgroundColor = XLColor.Cyan;
|
||||
|
||||
// Adjust the width
|
||||
ws.Columns("A:V").Width = 3;
|
||||
|
||||
var ws2 = workbook.Worksheets.Add("Columns of a worksheet");
|
||||
|
||||
// Contiguous columns by number
|
||||
ws2.Columns(1, 2).Style.Fill.BackgroundColor = XLColor.Red;
|
||||
|
||||
// Contiguous columns by letter
|
||||
ws2.Columns("D", "E").Style.Fill.BackgroundColor = XLColor.Blue;
|
||||
|
||||
// Contiguous columns by letter
|
||||
ws2.Columns("G:H").Style.Fill.BackgroundColor = XLColor.DeepPink;
|
||||
|
||||
// Spread columns by number
|
||||
ws2.Columns("10:11,13:14").Style.Fill.BackgroundColor = XLColor.Orange;
|
||||
|
||||
// Spread columns by letter
|
||||
ws2.Columns("P:Q,S:T").Style.Fill.BackgroundColor = XLColor.Turquoise;
|
||||
|
||||
// Use a single number/letter
|
||||
ws2.Columns("V").Style.Fill.BackgroundColor = XLColor.Cyan;
|
||||
|
||||
// Adjust the width
|
||||
ws2.Columns("A:V").Width = 3;
|
||||
|
||||
workbook.SaveAs(filePath);
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
// Override
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using ClosedXML.Excel;
|
||||
|
||||
|
||||
namespace ClosedXML_Examples.Columns
|
||||
{
|
||||
public class ColumnSettings : IXLExample
|
||||
{
|
||||
#region Variables
|
||||
|
||||
// Public
|
||||
|
||||
// Private
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
// Public
|
||||
|
||||
// Private
|
||||
|
||||
// Override
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
// Public
|
||||
public ColumnSettings()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Private
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
// Public
|
||||
|
||||
// Private
|
||||
|
||||
// Override
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
// Public
|
||||
public void Create(String filePath)
|
||||
{
|
||||
var workbook = new XLWorkbook();
|
||||
var ws = workbook.Worksheets.Add("Column Settings");
|
||||
|
||||
var col1 = ws.Column("B");
|
||||
col1.Style.Fill.BackgroundColor = XLColor.Red;
|
||||
col1.Width = 20;
|
||||
|
||||
var col2 = ws.Column(4);
|
||||
col2.Style.Fill.BackgroundColor = XLColor.DarkOrange;
|
||||
col2.Width = 5;
|
||||
|
||||
workbook.SaveAs(filePath);
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
// Override
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using ClosedXML.Excel;
|
||||
|
||||
|
||||
namespace ClosedXML_Examples
|
||||
{
|
||||
public class DeletingColumns : IXLExample
|
||||
{
|
||||
#region Variables
|
||||
|
||||
// Public
|
||||
|
||||
// Private
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
// Public
|
||||
|
||||
// Private
|
||||
|
||||
// Override
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
// Public
|
||||
|
||||
// Private
|
||||
|
||||
// Override
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
// Public
|
||||
public void Create(String filePath)
|
||||
{
|
||||
var workbook = new XLWorkbook();
|
||||
var ws = workbook.Worksheets.Add("Deleting Columns");
|
||||
|
||||
var rngTitles = ws.Range("B2:D2");
|
||||
ws.Row(1).InsertRowsBelow(2);
|
||||
|
||||
var rng1 = ws.Range("B2:D2");
|
||||
var rng2 = ws.Range("F2:G2");
|
||||
var rng3 = ws.Range("A1:A3");
|
||||
var col1 = ws.Column(1);
|
||||
|
||||
rng1.Style.Fill.BackgroundColor = XLColor.Orange;
|
||||
rng2.Style.Fill.BackgroundColor = XLColor.Blue;
|
||||
rng3.Style.Fill.BackgroundColor = XLColor.Red;
|
||||
col1.Style.Fill.BackgroundColor = XLColor.Black;
|
||||
|
||||
ws.Columns("A,C,E:H").Delete();
|
||||
ws.Cell("A2").Value = "OK";
|
||||
ws.Cell("B2").Value = "OK";
|
||||
|
||||
workbook.SaveAs(filePath);
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
// Override
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user