Class ExcelWorksheet
- Namespace
- OfficeOpenXml
- Assembly
- EPPlus.dll
Represents an Excel worksheet and provides access to its properties and methods
public class ExcelWorksheet : XmlHelper, IEqualityComparer<ExcelWorksheet>, IDisposable
- Inheritance
-
ExcelWorksheet
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
ExcelWorksheet(XmlNamespaceManager, ExcelPackage, string, Uri, string, int, int, eWorkSheetHidden?)
A worksheet
public ExcelWorksheet(XmlNamespaceManager ns, ExcelPackage excelPackage, string relID, Uri uriWorksheet, string sheetName, int sheetID, int positionID, eWorkSheetHidden? hide)
Parameters
ns
XmlNamespaceManagerNamespacemanager
excelPackage
ExcelPackagePackage
relID
stringRelationship ID
uriWorksheet
UriURI
sheetName
stringName of the sheet
sheetID
intSheet id
positionID
intPosition
hide
eWorkSheetHidden?hide
Properties
AutoFilter
Autofilter settings
public ExcelAutoFilter AutoFilter { get; }
Property Value
AutoFilterAddress
The auto filter address. null means no auto filter.
[Obsolete("AutoFilterAddress is deprecated please use AutoFilter.Address instead.")]
public ExcelAddressBase AutoFilterAddress { get; }
Property Value
BackgroundImage
An image displayed as the background of the worksheet.
public ExcelBackgroundImage BackgroundImage { get; }
Property Value
Cells
Provides access to a range of cells
public ExcelRange Cells { get; }
Property Value
CodeModule
The VBA code modul for the worksheet, if the package contains a VBA project. CreateVBAProject()
public ExcelVBAModule CodeModule { get; }
Property Value
Columns
A collection of column specific properties in the worksheet.
public ExcelColumnCollection Columns { get; }
Property Value
Comments
Collection of comments
public ExcelCommentCollection Comments { get; }
Property Value
ConditionalFormatting
ConditionalFormatting defined in the worksheet. Use the Add methods to create ConditionalFormatting and add them to the worksheet. Then set the properties on the instance returned.
public ExcelConditionalFormattingCollection ConditionalFormatting { get; }
Property Value
- See Also
CustomHeight
'True' if defaultRowHeight value has been manually set, or is different from the default value. Is automaticlly set to 'True' when assigning the DefaultRowHeight property
public bool CustomHeight { get; set; }
Property Value
DataValidations
DataValidation defined in the worksheet. Use the Add methods to create DataValidations and add them to the worksheet. Then set the properties on the instance returned. Must know worksheet or at least worksheet name to determine if extLst when user input DataValidations in API.
public ExcelDataValidationCollection DataValidations { get; }
Property Value
- See Also
DefaultColWidth
Get/set the default width of all columns in the worksheet
public double DefaultColWidth { get; set; }
Property Value
DefaultRowHeight
Get/set the default height of all rows in the worksheet
public double DefaultRowHeight { get; set; }
Property Value
Dimension
Dimension address for the worksheet for cells with a value or a style set. Top left cell to Bottom right. If the worksheet has no cells, null is returned
public ExcelRangeBase Dimension { get; }
Property Value
DimensionByValue
Dimension address for the worksheet for cells with a value different than null. Top left cell to Bottom right. If the worksheet has no cells, null is returned
public ExcelRangeBase DimensionByValue { get; }
Property Value
Drawings
Collection of drawing-objects like shapes, images and charts
public ExcelDrawings Drawings { get; }
Property Value
FirstValueCell
The first cell with a value in the worksheet that differs from null. Normally this is the top-left cell, unless the worksheet is set to RightToLeft mode. RightToLeft
public ExcelRangeBase FirstValueCell { get; }
Property Value
HeaderFooter
A reference to the header and footer class which allows you to set the header and footer for all odd, even and first pages of the worksheet
public ExcelHeaderFooter HeaderFooter { get; }
Property Value
Remarks
To format the text you can use the following format
Prefix | Description |
---|---|
&U | Underlined |
&E | Double Underline |
&K:xxxxxx | Color. ex &K:FF0000 for red |
&"Font,Regular Bold Italic" | Changes the font. Regular or Bold or Italic or Bold Italic can be used. ex &"Arial,Bold Italic" |
&nn | Change font size. nn is an integer. ex &24 |
&G | Placeholder for images. Images cannot be added by the library, but its possible to use in a template. |
Hidden
Indicates if the worksheet is hidden in the workbook
public eWorkSheetHidden Hidden { get; set; }
Property Value
IgnoredErrors
Ignore Errors for the specified ranges and error types.
public ExcelIgnoredErrorCollection IgnoredErrors { get; }
Property Value
Index
The index in the worksheets collection
public int Index { get; }
Property Value
LastValueCell
The last cell with a value in the worksheet that differs from null. Normally this is the bottom-right cell, unless the worksheet is set to RightToLeft mode. RightToLeft
public ExcelRangeBase LastValueCell { get; }
Property Value
MergedCells
Addresses to merged ranges
public ExcelWorksheet.MergeCellsCollection MergedCells { get; }
Property Value
Name
The worksheet's display name as it appears on the tab
public string Name { get; set; }
Property Value
Names
Provides access to named ranges
public ExcelNamedRangeCollection Names { get; }
Property Value
OutLineApplyStyle
Automatic styles
public bool OutLineApplyStyle { get; set; }
Property Value
OutLineSummaryBelow
If true, summary rows are showen below the details, otherwise above.
public bool OutLineSummaryBelow { get; set; }
Property Value
OutLineSummaryRight
If true, summary columns are to right of details otherwise to the left.
public bool OutLineSummaryRight { get; set; }
Property Value
PivotTables
Pivottables defined in the worksheet.
public ExcelPivotTableCollection PivotTables { get; }
Property Value
PrinterSettings
Printer settings
public ExcelPrinterSettings PrinterSettings { get; }
Property Value
ProtectedRanges
Access to protected ranges in the worksheet
public ExcelProtectedRangeCollection ProtectedRanges { get; }
Property Value
Protection
Access to sheet protection properties
public ExcelSheetProtection Protection { get; }
Property Value
RowZeroHeight
If true, empty rows are hidden by default. This reduces the size of the package and increases performance if most of the rows in a worksheet are hidden.
public bool RowZeroHeight { get; set; }
Property Value
Rows
A collection of row specific properties in the worksheet.
public ExcelRowsCollection Rows { get; }
Property Value
SelectedRange
Provides access to the selected range of cells
public ExcelRange SelectedRange { get; }
Property Value
SortState
Sets the sort state
public SortState SortState { get; }
Property Value
SparklineGroups
Collection of Sparkline-objects. Sparklines are small in-cell charts.
public ExcelSparklineGroupCollection SparklineGroups { get; }
Property Value
TabColor
Color of the sheet tab
public Color TabColor { get; set; }
Property Value
Tables
Tables defined in the worksheet.
public ExcelTableCollection Tables { get; }
Property Value
ThreadedComments
A collection of threaded comments referenced in the worksheet.
public ExcelWorksheetThreadedComments ThreadedComments { get; }
Property Value
View
Returns a ExcelWorksheetView object that allows you to set the view state properties of the worksheet
public ExcelWorksheetView View { get; }
Property Value
Workbook
The workbook object
public ExcelWorkbook Workbook { get; }
Property Value
WorksheetXml
The XML document holding the worksheet data. All column, row, cell, pagebreak, merged cell and hyperlink-data are loaded into memory and removed from the document when loading the document.
public XmlDocument WorksheetXml { get; }
Property Value
- XmlDocument
Methods
ClearFormulaValues()
Removes all values of cells with formulas in the entire worksheet, but keeps the formulas.
public void ClearFormulaValues()
ClearFormulas()
Removes all formulas within the entire worksheet, but keeps the calculated values.
public void ClearFormulas()
Column(int)
Provides access to an individual column within the worksheet so you can set its properties.
public ExcelColumn Column(int col)
Parameters
col
intThe column number in the worksheet
Returns
DeleteColumn(int)
Delete the specified column from the worksheet.
public void DeleteColumn(int column)
Parameters
column
intThe column to be deleted
DeleteColumn(int, int)
Delete the specified columns from the worksheet.
public void DeleteColumn(int columnFrom, int columns)
Parameters
DeleteRow(int)
Delete the specified row from the worksheet.
public void DeleteRow(int row)
Parameters
row
intA row to be deleted
DeleteRow(int, int)
Delete the specified rows from the worksheet.
public void DeleteRow(int rowFrom, int rows)
Parameters
DeleteRow(int, int, bool)
Deletes the specified rows from the worksheet.
[Obsolete("Use the two-parameter method instead")]
public void DeleteRow(int rowFrom, int rows, bool shiftOtherRowsUp)
Parameters
rowFrom
intThe number of the start row to be deleted
rows
intNumber of rows to delete
shiftOtherRowsUp
boolNot used. Rows are always shifted
Dispose()
Disposes the worksheet
public void Dispose()
Equals(ExcelWorksheet, ExcelWorksheet)
Check if a worksheet is equal to another
public bool Equals(ExcelWorksheet x, ExcelWorksheet y)
Parameters
x
ExcelWorksheetFirst worksheet
y
ExcelWorksheetSecond worksheet
Returns
GetFormulaRange(int, int)
Gets the range for the formula in the cell. A shared formula will return the range for the entire series. An array formula will return the range of the output of the formula. If you want the range of a dynamic array formula, you must calculate the formula first.
public ExcelRangeBase GetFormulaRange(int row, int column)
Parameters
row
intThe row of the cell containing the formula.
column
intThe column of the cell containing the formula.
Returns
- ExcelRangeBase
The range the formula spans
GetHashCode(ExcelWorksheet)
Returns a hashcode generated from the WorksheetXml
public int GetHashCode(ExcelWorksheet obj)
Parameters
obj
ExcelWorksheetThe worksheet
Returns
- int
The hashcode
GetMergeCellId(int, int)
Get MergeCell Index No
public int GetMergeCellId(int row, int column)
Parameters
Returns
GetValue(int, int)
Get the cell value from the worksheet
public object GetValue(int Row, int Column)
Parameters
Returns
- object
The value
GetValue<T>(int, int)
Get a strongly typed cell value from the worksheet
public T GetValue<T>(int Row, int Column)
Parameters
Returns
- T
The value. If the value can't be converted to the specified type, the default value will be returned
Type Parameters
T
The type
InsertColumn(int, int)
Inserts new columns into the spreadsheet. Existing columns below the position are shifted down. All formula are updated to take account of the new column(s).
public void InsertColumn(int columnFrom, int columns)
Parameters
InsertColumn(int, int, int)
Inserts new columns into the spreadsheet. Existing column to the left are shifted. All formula are updated to take account of the new column(s).
public void InsertColumn(int columnFrom, int columns, int copyStylesFromColumn)
Parameters
columnFrom
intThe position of the new column(s)
columns
intNumber of columns to insert.
copyStylesFromColumn
intCopy Styles from this column. Applied to all inserted columns
InsertRow(int, int)
Inserts new rows into the spreadsheet. Existing rows below the position are shifted down. All formula are updated to take account of the new row(s).
public void InsertRow(int rowFrom, int rows)
Parameters
InsertRow(int, int, int)
Inserts new rows into the spreadsheet. Existing rows below the position are shifted down. All formula are updated to take account of the new row(s).
public void InsertRow(int rowFrom, int rows, int copyStylesFromRow)
Parameters
rowFrom
intThe position of the new row(s)
rows
intNumber of rows to insert.
copyStylesFromRow
intCopy Styles from this row. Applied to all inserted rows
Row(int)
Provides access to an individual row within the worksheet so you can set its properties.
public ExcelRow Row(int row)
Parameters
row
intThe row number in the worksheet
Returns
Select()
Make the current worksheet active.
public void Select()
Select(ExcelAddress)
Selects a range in the worksheet. The active cell is the topmost cell of the first address. Make the current worksheet active.
public void Select(ExcelAddress Address)
Parameters
Address
ExcelAddressAn address range
Select(ExcelAddress, bool)
Selects a range in the worksheet. The active cell is the topmost cell of the first address.
public void Select(ExcelAddress Address, bool SelectSheet)
Parameters
Address
ExcelAddressA range of cells
SelectSheet
boolMake the sheet active
Select(string)
Selects a range in the worksheet. The active cell is the topmost cell. Make the current worksheet active.
public void Select(string Address)
Parameters
Address
stringAn address range
Select(string, bool)
Selects a range in the worksheet. The actice cell is the topmost cell.
public void Select(string Address, bool SelectSheet)
Parameters
SetValue(int, int, object)
Set the value of a cell
public void SetValue(int Row, int Column, object Value)
Parameters
SetValue(string, object)
Set the value of a cell
public void SetValue(string Address, object Value)
Parameters
ToString()
Returns the name of the worksheet
public override string ToString()
Returns
- string
The name of the worksheet