Class XLWorkbook
public class XLWorkbook : IXLWorkbook, IXLProtectable<IXLWorkbookProtection, XLWorkbookProtectionElements>, IXLProtectable, IDisposable
- Inheritance
-
XLWorkbook
- Implements
- Inherited Members
- Extension Methods
Constructors
XLWorkbook()
Creates a new Excel workbook.
public XLWorkbook()
XLWorkbook(LoadOptions)
public XLWorkbook(LoadOptions loadOptions)
Parameters
loadOptionsLoadOptions
XLWorkbook(Stream)
Opens an existing workbook from a stream.
public XLWorkbook(Stream stream)
Parameters
streamStreamThe stream to open.
XLWorkbook(Stream, LoadOptions)
public XLWorkbook(Stream stream, LoadOptions loadOptions)
Parameters
streamStreamloadOptionsLoadOptions
XLWorkbook(string)
Opens an existing workbook from a file.
public XLWorkbook(string file)
Parameters
filestringThe file to open.
XLWorkbook(string, LoadOptions)
public XLWorkbook(string file, LoadOptions loadOptions)
Parameters
filestringloadOptionsLoadOptions
Properties
Author
public string Author { get; set; }
Property Value
CalculateMode
Gets or sets the workbook's calculation mode.
public XLCalculateMode CalculateMode { get; set; }
Property Value
CalculationOnSave
public bool CalculationOnSave { get; set; }
Property Value
CellSetValueBehavior
Behavior for Value.set
public static XLCellSetValueBehavior CellSetValueBehavior { get; set; }
Property Value
Chartsheets
Gets an object to manipulate the chartsheets.
public IXLChartsheets Chartsheets { get; }
Property Value
ColumnWidth
Gets or sets the default column width for the workbook.
All new worksheets will use this column width.
public double ColumnWidth { get; set; }
Property Value
CustomProperties
public IXLCustomProperties CustomProperties { get; }
Property Value
DefaultColumnWidth
public static double DefaultColumnWidth { get; }
Property Value
DefaultOutline
public static IXLOutline DefaultOutline { get; }
Property Value
DefaultPageOptions
public static IXLPageSetup DefaultPageOptions { get; }
Property Value
DefaultRightToLeft
public bool DefaultRightToLeft { get; }
Property Value
DefaultRowHeight
public static double DefaultRowHeight { get; }
Property Value
DefaultShowFormulas
public bool DefaultShowFormulas { get; }
Property Value
DefaultShowGridLines
public bool DefaultShowGridLines { get; }
Property Value
DefaultShowOutlineSymbols
public bool DefaultShowOutlineSymbols { get; }
Property Value
DefaultShowRowColHeaders
public bool DefaultShowRowColHeaders { get; }
Property Value
DefaultShowRuler
public bool DefaultShowRuler { get; }
Property Value
DefaultShowWhiteSpace
public bool DefaultShowWhiteSpace { get; }
Property Value
DefaultShowZeros
public bool DefaultShowZeros { get; }
Property Value
DefaultStyle
public static IXLStyle DefaultStyle { get; }
Property Value
FileSharing
public IXLFileSharing FileSharing { get; }
Property Value
ForceFullCalculation
public bool ForceFullCalculation { get; set; }
Property Value
FullCalculationOnLoad
public bool FullCalculationOnLoad { get; set; }
Property Value
FullPrecision
public bool FullPrecision { get; set; }
Property Value
IsPasswordProtected
Gets a value indicating whether this instance is protected with a password.
public bool IsPasswordProtected { get; }
Property Value
- bool
trueif this instance is password protected; otherwise,false.
IsProtected
Gets a value indicating whether this instance is protected, either with or without a password.
public bool IsProtected { get; }
Property Value
- bool
trueif this instance is protected; otherwise,false.
LockStructure
public bool LockStructure { get; set; }
Property Value
LockWindows
public bool LockWindows { get; set; }
Property Value
NamedRanges
Gets an object to manipulate this workbook's named ranges.
public IXLNamedRanges NamedRanges { get; }
Property Value
Outline
Gets or sets the default outline options for the workbook.
All new worksheets will use these outline options.
public IXLOutline Outline { get; set; }
Property Value
PageOptions
Gets or sets the default page options for the workbook.
All new worksheets will use these page options.
public IXLPageSetup PageOptions { get; set; }
Property Value
PivotCaches
All pivot caches in the workbook, whether they have a pivot table or not.
public IXLPivotCaches PivotCaches { get; }
Property Value
PredefinedStyles
public IXLPredefinedStyles PredefinedStyles { get; }
Property Value
Properties
Gets or sets the workbook's properties.
public XLWorkbookProperties Properties { get; set; }
Property Value
ReferenceStyle
Gets or sets the workbook's reference style.
public XLReferenceStyle ReferenceStyle { get; set; }
Property Value
RightToLeft
public bool RightToLeft { get; set; }
Property Value
RowHeight
Gets or sets the default row height for the workbook.
All new worksheets will use this row height.
public double RowHeight { get; set; }
Property Value
Sheets
Gets an object to manipulate the sheets.
public IXLSheets Sheets { get; }
Property Value
ShowFormulas
public bool ShowFormulas { get; set; }
Property Value
ShowGridLines
public bool ShowGridLines { get; set; }
Property Value
ShowOutlineSymbols
public bool ShowOutlineSymbols { get; set; }
Property Value
ShowRowColHeaders
public bool ShowRowColHeaders { get; set; }
Property Value
ShowRuler
public bool ShowRuler { get; set; }
Property Value
ShowWhiteSpace
public bool ShowWhiteSpace { get; set; }
Property Value
ShowZeros
public bool ShowZeros { get; set; }
Property Value
Style
Gets or sets the default style for the workbook.
All new worksheets will use this style.
public IXLStyle Style { get; set; }
Property Value
Theme
Gets an object to manipulate this workbook's theme.
public IXLTheme Theme { get; }
Property Value
Use1904DateSystem
public bool Use1904DateSystem { get; set; }
Property Value
Worksheets
Gets an object to manipulate the worksheets.
public IXLWorksheets Worksheets { get; }
Property Value
Methods
AddChartsheet()
public IXLChartsheet AddChartsheet()
Returns
AddChartsheet(IXLChartsheet)
public void AddChartsheet(IXLChartsheet chartsheet)
Parameters
chartsheetIXLChartsheet
AddChartsheet(int)
public IXLChartsheet AddChartsheet(int position)
Parameters
positionint
Returns
AddChartsheet(string)
public IXLChartsheet AddChartsheet(string sheetName)
Parameters
sheetNamestring
Returns
AddChartsheet(string, int)
public IXLChartsheet AddChartsheet(string sheetName, int position)
Parameters
Returns
AddWorksheet()
public IXLWorksheet AddWorksheet()
Returns
AddWorksheet(IXLWorksheet)
public void AddWorksheet(IXLWorksheet worksheet)
Parameters
worksheetIXLWorksheet
AddWorksheet(DataSet)
public void AddWorksheet(DataSet dataSet)
Parameters
dataSetDataSet
AddWorksheet(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}.
public IXLWorksheet AddWorksheet(DataTable dataTable)
Parameters
dataTableDataTableDatatable to insert
Returns
- IXLWorksheet
Inserted Worksheet
AddWorksheet(DataTable, string)
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}.
public IXLWorksheet AddWorksheet(DataTable dataTable, string sheetName)
Parameters
dataTableDataTabledataTable to insert as Excel Table
sheetNamestringWorksheet and Excel Table name
Returns
- IXLWorksheet
Inserted Worksheet
AddWorksheet(DataTable, string, string)
Add a worksheet with a table at Cell(row:1, column:1).
public IXLWorksheet AddWorksheet(DataTable dataTable, string sheetName, string tableName)
Parameters
dataTableDataTabledataTable to insert as Excel Table
sheetNamestringWorksheet name
tableNamestringExcel Table name
Returns
- IXLWorksheet
Inserted Worksheet
AddWorksheet(int)
public IXLWorksheet AddWorksheet(int position)
Parameters
positionint
Returns
AddWorksheet(string)
public IXLWorksheet AddWorksheet(string sheetName)
Parameters
sheetNamestring
Returns
AddWorksheet(string, int)
public IXLWorksheet AddWorksheet(string sheetName, int position)
Parameters
Returns
Cell(string)
public IXLCell Cell(string namedCell)
Parameters
namedCellstring
Returns
CellFromFullAddress(string, out IXLWorksheet)
public IXLCell CellFromFullAddress(string cellAddress, out IXLWorksheet ws)
Parameters
cellAddressstringwsIXLWorksheet
Returns
Cells(string)
public IXLCells Cells(string namedCells)
Parameters
namedCellsstring
Returns
Chartsheet(int)
public IXLChartsheet Chartsheet(int position)
Parameters
positionint
Returns
Chartsheet(string)
public IXLChartsheet Chartsheet(string name)
Parameters
namestring
Returns
CreateEmptyStyle()
public IXLStyle CreateEmptyStyle()
Returns
CustomProperty(string)
public IXLCustomProperty CustomProperty(string name)
Parameters
namestring
Returns
Dispose()
public void Dispose()
Evaluate(string)
Evaluate a formula expression.
public XLCellValue Evaluate(string expression)
Parameters
expressionstringFormula expression to evaluate.
Returns
Exceptions
- MissingContextException
If the expression contains a function that requires a context (e.g. current cell or worksheet).
EvaluateExpr(string)
Evaluate a formula and return a value. Formulas with references don't work and culture used for conversion is invariant.
public static XLCellValue EvaluateExpr(string expression)
Parameters
expressionstring
Returns
FindCells(Func<IXLCell, bool>)
public IXLCells FindCells(Func<IXLCell, bool> predicate)
Parameters
Returns
FindColumns(Func<IXLColumn, bool>)
public IXLColumns FindColumns(Func<IXLColumn, bool> predicate)
Parameters
Returns
FindRows(Func<IXLRow, bool>)
public IXLRows FindRows(Func<IXLRow, bool> predicate)
Parameters
Returns
GetAnchorFromImageId(DrawingsPart, string)
public static OpenXmlElement GetAnchorFromImageId(DrawingsPart drawingsPart, string relId)
Parameters
drawingsPartDrawingsPartrelIdstring
Returns
GetAnchorFromImageIndex(WorksheetPart, int)
public static OpenXmlElement GetAnchorFromImageIndex(WorksheetPart worksheetPart, int index)
Parameters
worksheetPartWorksheetPartindexint
Returns
GetImageRelIdFromAnchor(OpenXmlElement)
public static string GetImageRelIdFromAnchor(OpenXmlElement anchor)
Parameters
anchorOpenXmlElement
Returns
GetPropertiesFromAnchor(OpenXmlElement)
public static NonVisualDrawingProperties GetPropertiesFromAnchor(OpenXmlElement anchor)
Parameters
anchorOpenXmlElement
Returns
NamedRange(string)
public IXLNamedRange NamedRange(string rangeName)
Parameters
rangeNamestring
Returns
OpenFromTemplate(string)
public static XLWorkbook OpenFromTemplate(string path)
Parameters
pathstring
Returns
Protect(Algorithm)
Protects this instance without a password.
public IXLWorkbookProtection Protect(XLProtectionAlgorithm.Algorithm algorithm = Algorithm.SimpleHash)
Parameters
algorithmXLProtectionAlgorithm.Algorithm
Returns
Protect(Algorithm, XLWorkbookProtectionElements)
public IXLWorkbookProtection Protect(XLProtectionAlgorithm.Algorithm algorithm, XLWorkbookProtectionElements allowedElements)
Parameters
algorithmXLProtectionAlgorithm.AlgorithmallowedElementsXLWorkbookProtectionElements
Returns
Protect(XLWorkbookProtectionElements)
public IXLWorkbookProtection Protect(XLWorkbookProtectionElements allowedElements)
Parameters
allowedElementsXLWorkbookProtectionElements
Returns
Protect(string, Algorithm)
Protects this instance using the specified password and password hash algorithm.
public IXLWorkbookProtection Protect(string password, XLProtectionAlgorithm.Algorithm algorithm = Algorithm.SimpleHash)
Parameters
passwordstringThe password.
algorithmXLProtectionAlgorithm.AlgorithmThe algorithm.
Returns
Protect(string, Algorithm, XLWorkbookProtectionElements)
public IXLWorkbookProtection Protect(string password, XLProtectionAlgorithm.Algorithm algorithm, XLWorkbookProtectionElements allowedElements)
Parameters
passwordstringalgorithmXLProtectionAlgorithm.AlgorithmallowedElementsXLWorkbookProtectionElements
Returns
Range(string)
public IXLRange Range(string range)
Parameters
rangestring
Returns
RangeFromFullAddress(string, out IXLWorksheet)
public IXLRange RangeFromFullAddress(string rangeAddress, out IXLWorksheet ws)
Parameters
rangeAddressstringwsIXLWorksheet
Returns
Ranges(string)
public IXLRanges Ranges(string ranges)
Parameters
rangesstring
Returns
RecalculateAllFormulas()
Force recalculation of all cell formulas.
public void RecalculateAllFormulas()
Save()
Saves the current workbook.
public void Save()
Save(SaveOptions)
public void Save(SaveOptions options)
Parameters
optionsSaveOptions
Save(bool, bool)
Saves the current workbook and optionally performs validation
public void Save(bool validate, bool evaluateFormulae = false)
Parameters
SaveAs(Stream)
Saves the current workbook to a stream.
public void SaveAs(Stream stream)
Parameters
streamStream
SaveAs(Stream, SaveOptions)
public void SaveAs(Stream stream, SaveOptions options)
Parameters
streamStreamoptionsSaveOptions
SaveAs(Stream, bool, bool)
Saves the current workbook to a stream and optionally validates it.
public void SaveAs(Stream stream, bool validate, bool evaluateFormulae = false)
Parameters
SaveAs(string)
Saves the current workbook to a file.
public void SaveAs(string file)
Parameters
filestring
SaveAs(string, SaveOptions)
public void SaveAs(string file, SaveOptions options)
Parameters
filestringoptionsSaveOptions
SaveAs(string, bool, bool)
Saves the current workbook to a file and optionally validates it.
public void SaveAs(string file, bool validate, bool evaluateFormulae = false)
Parameters
Search(string, CompareOptions, bool)
Searches the cells' contents for a given piece of text
public IEnumerable<IXLCell> Search(string searchText, CompareOptions compareOptions = CompareOptions.Ordinal, bool searchFormulae = false)
Parameters
searchTextstringThe search text.
compareOptionsCompareOptionsThe compare options.
searchFormulaeboolif set to
truesearch formulae instead of cell values.
Returns
SetLockStructure(bool)
public XLWorkbook SetLockStructure(bool value)
Parameters
valuebool
Returns
SetLockWindows(bool)
public XLWorkbook SetLockWindows(bool value)
Parameters
valuebool
Returns
SetUse1904DateSystem()
public XLWorkbook SetUse1904DateSystem()
Returns
SetUse1904DateSystem(bool)
public XLWorkbook SetUse1904DateSystem(bool value)
Parameters
valuebool
Returns
Sheet(int)
public IXLSheet Sheet(int position)
Parameters
positionint
Returns
Sheet(string)
public IXLSheet Sheet(string name)
Parameters
namestring
Returns
Table(string, StringComparison)
Gets the Excel table of the given name
public IXLTable Table(string tableName, StringComparison comparisonType = StringComparison.OrdinalIgnoreCase)
Parameters
tableNamestringName of the table to return.
comparisonTypeStringComparisonOne of the enumeration values that specifies how the strings will be compared.
Returns
- IXLTable
The table with given name
Exceptions
- ArgumentOutOfRangeException
If no tables with this name could be found in the workbook.
ToString()
public override string ToString()
Returns
TryGetChartsheet(string, out IXLChartsheet)
public bool TryGetChartsheet(string name, out IXLChartsheet chartsheet)
Parameters
namestringchartsheetIXLChartsheet
Returns
TryGetSheet(string, out IXLSheet)
public bool TryGetSheet(string name, out IXLSheet sheet)
Parameters
Returns
TryGetWorksheet(string, out IXLWorksheet)
public bool TryGetWorksheet(string name, out IXLWorksheet worksheet)
Parameters
namestringworksheetIXLWorksheet
Returns
Unprotect()
Unprotects this instance without a password.
public IXLWorkbookProtection Unprotect()
Returns
Unprotect(string)
Unprotects this instance using the specified password.
public IXLWorkbookProtection Unprotect(string password)
Parameters
passwordstringThe password.
Returns
Worksheet(int)
public IXLWorksheet Worksheet(int position)
Parameters
positionint
Returns
Worksheet(string)
public IXLWorksheet Worksheet(string name)
Parameters
namestring