Workbook

interface ClosedXML.Excel.IXLWorkbook : IXLProtectable<IXLWorkbookProtection, XLWorkbookProtectionElements>, IDisposable

Subclassed by XLWorkbook

Public Functions

IXLWorksheet AddWorksheet (DataTable dataTable)

Add a worksheet with a table at Cell(row:1, column:1). The dataTable’s name is used for the worksheet name. The name of a table will be generated as Table{number suffix}.

Param dataTable

Datatable to insert

Return

Inserted Worksheet

IXLWorksheet AddWorksheet (DataTable dataTable, String sheetName)

Add a worksheet with a table at Cell(row:1, column:1). The sheetName provided is used for the worksheet name. The name of a table will be generated as Table{number suffix}.

Param dataTable

dataTable to insert as Excel Table

Param sheetName

Worksheet and Excel Table name

Return

Inserted Worksheet

IXLWorksheet AddWorksheet (DataTable dataTable, String sheetName, String tableName)

Add a worksheet with a table at Cell(row:1, column:1).

Param dataTable

dataTable to insert as Excel Table

Param sheetName

Worksheet name

Param tableName

Excel Table name

Return

Inserted Worksheet

XLCellValue Evaluate (String expression)

Evaluate a formula expression.

Param expression

Formula expression to evaluate.

Throws MissingContextException

If the expression contains a function that requires a context (e.g. current cell or worksheet).

IXLDefinedName? DefinedName (String name)

Try to find a defined name. If name specifies a sheet, try to find name in the sheet first and fall back to the workbook if not found in the sheet.

Requested name Sheet1!Name will first try to find Name in a sheet Sheet1 (if such sheet exists) and if not found there, tries to find Name in workbook.

Requested name Name will be searched only in a workbooks DefinedNames.

Param name

Name of requested name, either plain name (e.g. Name) or with sheet specified (e.g. Sheet!Name).

Return

Found name or null.

void RecalculateAllFormulas ()

Force recalculation of all cell formulas.

void Save ()

Saves the current workbook.

void Save (Boolean validate, Boolean evaluateFormulae = false)

Saves the current workbook and optionally performs validation

void SaveAs (String file)

Saves the current workbook to a file.

void SaveAs (String file, Boolean validate, Boolean evaluateFormulae = false)

Saves the current workbook to a file and optionally validates it.

void SaveAs (Stream stream)

Saves the current workbook to a stream.

void SaveAs (Stream stream, Boolean validate, Boolean evaluateFormulae = false)

Saves the current workbook to a stream and optionally validates it.

IEnumerable<IXLCell> Search (String searchText, CompareOptions compareOptions = CompareOptions.Ordinal, Boolean searchFormulae = false)

Searches the cells’ contents for a given piece of text

Param searchText

The search text.

Param compareOptions

The compare options.

Param searchFormulae

if set to true search formulae instead of cell values.

IXLTable Table (String tableName, StringComparison comparisonType = StringComparison.OrdinalIgnoreCase)

Gets the Excel table of the given name

Param tableName

Name of the table to return.

Param comparisonType

One of the enumeration values that specifies how the strings will be compared.

Throws ArgumentOutOfRangeException

If no tables with this name could be found in the workbook.

Return

The table with given name

Properties

XLCalculateMode CalculateMode { get; set; }

Gets or sets the workbook’s calculation mode.

Double ColumnWidth { get; set; }

Gets or sets the default column width for the workbook.

All new worksheets will use this column width.

IXLDefinedNames DefinedNames { get; set; }

Gets an object to manipulate this workbook’s defined names.

IXLOutline Outline { get; set; }

Gets or sets the default outline options for the workbook.

All new worksheets will use these outline options.

IXLPageSetup PageOptions { get; set; }

Gets or sets the default page options for the workbook.

All new worksheets will use these page options.

IXLPivotCaches PivotCaches { get; set; }

Gets all pivot caches in a workbook. A one cache can be used by multiple tables. Unused caches are not saved.

XLWorkbookProperties Properties { get; set; }

Gets or sets the workbook’s properties.

XLReferenceStyle ReferenceStyle { get; set; }

Gets or sets the workbook’s reference style.

Double RowHeight { get; set; }

Gets or sets the default row height for the workbook.

All new worksheets will use this row height.

IXLStyle Style { get; set; }

Gets or sets the default style for the workbook.

All new worksheets will use this style.

IXLTheme Theme { get; set; }

Gets an object to manipulate this workbook’s theme.

IXLWorksheets Worksheets { get; set; }

Gets an object to manipulate the worksheets.