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,48 @@
|
||||
using ClosedXML.Excel;
|
||||
using MoreLinq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
// TODO: Add example to Wiki
|
||||
|
||||
namespace ClosedXML_Examples.Tables
|
||||
{
|
||||
public class ResizingTables : IXLExample
|
||||
{
|
||||
public void Create(string filePath)
|
||||
{
|
||||
using (var wb = new XLWorkbook())
|
||||
{
|
||||
var ws1 = wb.AddWorksheet("Sheet1");
|
||||
|
||||
var data1 = Enumerable.Range(1, 10)
|
||||
.Select(i =>
|
||||
new
|
||||
{
|
||||
Index = i,
|
||||
Character = Convert.ToChar(64 + i),
|
||||
String = new String('a', i),
|
||||
Integer = 64 + i
|
||||
});
|
||||
|
||||
var table1 = ws1.Cell("B2").InsertTable(data1, true)
|
||||
.SetShowHeaderRow()
|
||||
.SetShowTotalsRow();
|
||||
|
||||
table1.Fields.First().TotalsRowLabel = "Sum of Integer";
|
||||
table1.Fields.Last().TotalsRowFunction = XLTotalsRowFunction.Sum;
|
||||
|
||||
var ws2 = ws1.CopyTo("Sheet2");
|
||||
var table2 = ws2.Tables.First();
|
||||
table2.Resize(table2.FirstCell(), table2.LastCell().CellLeft().CellAbove(3));
|
||||
|
||||
var ws3 = ws2.CopyTo("Sheet3");
|
||||
var table3 = ws3.Tables.First();
|
||||
table3.Resize(table3.FirstCell().CellLeft(), table3.LastCell().CellRight().CellBelow(1));
|
||||
|
||||
wb.Worksheets.ForEach(ws => ws.Columns().AdjustToContents());
|
||||
wb.SaveAs(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user