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.
109 lines
2.6 KiB
C#
109 lines
2.6 KiB
C#
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
|
|
}
|
|
}
|