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,65 @@
|
||||
using System;
|
||||
using ClosedXML.Excel;
|
||||
|
||||
|
||||
namespace ClosedXML_Examples.PageSetup
|
||||
{
|
||||
public class HeaderFooters : IXLExample
|
||||
{
|
||||
#region Methods
|
||||
|
||||
// Public
|
||||
public void Create(String filePath)
|
||||
{
|
||||
var workbook = new XLWorkbook();
|
||||
var ws = workbook.Worksheets.Add("Headers and Footers");
|
||||
|
||||
// Simple left header to be placed on all pages
|
||||
ws.PageSetup.Header.Left.AddText("Created with ClosedXML");
|
||||
|
||||
// Using various font decorations for the right header on the first page only
|
||||
// Here we show different methods for setting font decorations.
|
||||
|
||||
// Set single font decorations immediately
|
||||
ws.PageSetup.Header.Right.AddText("The ", XLHFOccurrence.FirstPage).SetBold();
|
||||
ws.PageSetup.Header.Right.AddText("First ", XLHFOccurrence.FirstPage).SetFontColor(XLColor.Red);
|
||||
|
||||
// Use the IXLRichText returned by the AddText(...) method to later on modify the font
|
||||
var richText = ws.PageSetup.Header.Right.AddText("Colorful ", XLHFOccurrence.FirstPage);
|
||||
richText.FontColor = XLColor.Blue;
|
||||
richText.Underline = XLFontUnderlineValues.Double;
|
||||
|
||||
// Set multiple font decorations chained
|
||||
ws.PageSetup.Header.Right.AddText("Page", XLHFOccurrence.FirstPage)
|
||||
.SetBold()
|
||||
.SetItalic()
|
||||
.SetFontName("Broadway");
|
||||
|
||||
|
||||
// Using predefined header/footer text:
|
||||
|
||||
// Let's put the full path to the file on the right footer of every odd page:
|
||||
ws.PageSetup.Footer.Right.AddText(XLHFPredefinedText.FullPath, XLHFOccurrence.OddPages);
|
||||
|
||||
// Let's put the current page number and total pages on the center of every footer:
|
||||
ws.PageSetup.Footer.Center.AddText(XLHFPredefinedText.PageNumber, XLHFOccurrence.AllPages);
|
||||
ws.PageSetup.Footer.Center.AddText(" / ", XLHFOccurrence.AllPages);
|
||||
ws.PageSetup.Footer.Center.AddText(XLHFPredefinedText.NumberOfPages, XLHFOccurrence.AllPages);
|
||||
|
||||
// Don't align headers and footers with the margins
|
||||
ws.PageSetup.AlignHFWithMargins = false;
|
||||
|
||||
// Don't scale headers and footers with the document
|
||||
ws.PageSetup.ScaleHFWithDocument = false;
|
||||
|
||||
workbook.SaveAs(filePath);
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
// Override
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using ClosedXML.Excel;
|
||||
|
||||
|
||||
namespace ClosedXML_Examples.PageSetup
|
||||
{
|
||||
public class Margins : IXLExample
|
||||
{
|
||||
#region Methods
|
||||
|
||||
// Public
|
||||
public void Create(String filePath)
|
||||
{
|
||||
var workbook = new XLWorkbook();
|
||||
var ws = workbook.Worksheets.Add("Margins");
|
||||
ws.PageSetup.Margins.Top = 1;
|
||||
ws.PageSetup.Margins.Bottom = 1.25;
|
||||
ws.PageSetup.Margins.Left = 0.5;
|
||||
ws.PageSetup.Margins.Right = 0.75;
|
||||
ws.PageSetup.Margins.Footer = 0.15;
|
||||
ws.PageSetup.Margins.Header = 0.30;
|
||||
|
||||
ws.PageSetup.CenterHorizontally = true;
|
||||
ws.PageSetup.CenterVertically = true;
|
||||
|
||||
workbook.SaveAs(filePath);
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
// Override
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using ClosedXML.Excel;
|
||||
|
||||
|
||||
namespace ClosedXML_Examples.PageSetup
|
||||
{
|
||||
public class Page : IXLExample
|
||||
{
|
||||
#region Methods
|
||||
|
||||
// Public
|
||||
public void Create(String filePath)
|
||||
{
|
||||
var workbook = new XLWorkbook();
|
||||
var ws1 = workbook.Worksheets.Add("Page Setup - Page1");
|
||||
ws1.PageSetup.PageOrientation = XLPageOrientation.Landscape;
|
||||
ws1.PageSetup.AdjustTo(80);
|
||||
ws1.PageSetup.PaperSize = XLPaperSize.LegalPaper;
|
||||
ws1.PageSetup.VerticalDpi = 600;
|
||||
ws1.PageSetup.HorizontalDpi = 600;
|
||||
|
||||
var ws2 = workbook.Worksheets.Add("Page Setup - Page2");
|
||||
ws2.PageSetup.PageOrientation = XLPageOrientation.Portrait;
|
||||
ws2.PageSetup.FitToPages(2, 2); // Alternatively you can use
|
||||
// ws2.PageSetup.PagesTall = #
|
||||
// and/or ws2.PageSetup.PagesWide = #
|
||||
|
||||
ws2.PageSetup.PaperSize = XLPaperSize.LetterPaper;
|
||||
ws2.PageSetup.VerticalDpi = 600;
|
||||
ws2.PageSetup.HorizontalDpi = 600;
|
||||
ws2.PageSetup.FirstPageNumber = 5;
|
||||
|
||||
workbook.SaveAs(filePath);
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
// Override
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using ClosedXML.Excel;
|
||||
|
||||
|
||||
namespace ClosedXML_Examples.PageSetup
|
||||
{
|
||||
public class SheetTab : IXLExample
|
||||
{
|
||||
#region Methods
|
||||
|
||||
// Public
|
||||
public void Create(String filePath)
|
||||
{
|
||||
var workbook = new XLWorkbook();
|
||||
var ws = workbook.Worksheets.Add("Sheet Tab");
|
||||
|
||||
// Adding print areas
|
||||
ws.PageSetup.PrintAreas.Add("A1:B2");
|
||||
ws.PageSetup.PrintAreas.Add("D3:D5");
|
||||
|
||||
// Adding rows to repeat at top
|
||||
ws.PageSetup.SetRowsToRepeatAtTop(1,2);
|
||||
|
||||
// Adding columns to repeat at left
|
||||
ws.PageSetup.SetColumnsToRepeatAtLeft(1, 2);
|
||||
|
||||
// Show gridlines
|
||||
ws.PageSetup.ShowGridlines = true;
|
||||
|
||||
// Print in black and white
|
||||
ws.PageSetup.BlackAndWhite = true;
|
||||
|
||||
// Print in draft quality
|
||||
ws.PageSetup.DraftQuality = true;
|
||||
|
||||
// Show row and column headings
|
||||
ws.PageSetup.ShowRowAndColumnHeadings = true;
|
||||
|
||||
// Set the page print order to over, then down
|
||||
ws.PageSetup.PageOrder = XLPageOrderValues.OverThenDown;
|
||||
|
||||
// Place comments at the end of the sheet
|
||||
ws.PageSetup.ShowComments = XLShowCommentsValues.AtEnd;
|
||||
|
||||
// Print errors as #N/A
|
||||
ws.PageSetup.PrintErrorValue = XLPrintErrorValues.NA;
|
||||
|
||||
workbook.SaveAs(filePath);
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
// Override
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using ClosedXML.Excel;
|
||||
|
||||
|
||||
namespace ClosedXML_Examples.PageSetup
|
||||
{
|
||||
public class Sheets : IXLExample
|
||||
{
|
||||
#region Methods
|
||||
|
||||
// Public
|
||||
public void Create(String filePath)
|
||||
{
|
||||
var workbook = new XLWorkbook();
|
||||
var ws1 = workbook.Worksheets.Add("Separate PrintAreas");
|
||||
ws1.PageSetup.PrintAreas.Add("A1:B2");
|
||||
ws1.PageSetup.PrintAreas.Add("D3:D5");
|
||||
|
||||
var ws2 = workbook.Worksheets.Add("Page Breaks");
|
||||
ws2.PageSetup.PrintAreas.Add("A1:D5");
|
||||
ws2.PageSetup.AddHorizontalPageBreak(2);
|
||||
ws2.PageSetup.AddVerticalPageBreak(2);
|
||||
|
||||
workbook.SaveAs(filePath);
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
// Override
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ClosedXML.Excel;
|
||||
|
||||
|
||||
namespace ClosedXML_Examples.PageSetup
|
||||
{
|
||||
public class TwoPages : IXLExample
|
||||
{
|
||||
#region Methods
|
||||
|
||||
// Public
|
||||
public void Create(String filePath)
|
||||
{
|
||||
var wb = new XLWorkbook();
|
||||
var ws = wb.Worksheets.Add("Sheet1");
|
||||
foreach (var ro in Enumerable.Range(1, 100))
|
||||
{
|
||||
foreach (var co in Enumerable.Range(1, 10))
|
||||
{
|
||||
ws.Cell(ro, co).Value = ws.Cell(ro, co).Address.ToString();
|
||||
}
|
||||
}
|
||||
ws.PageSetup.PagesWide = 1;
|
||||
|
||||
wb.SaveAs(filePath);
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
// Override
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user