Class Worksheet
public class Worksheet : XlsWorksheet, IDisposable, INamedObject, ICloneParent, IInternalWorksheet, IWorksheet, ITabSheet, IExcelApplication
- Inheritance
-
Worksheet
- Implements
- Inherited Members
Properties
AllocatedRange
Returns a Range object that represents the used range on the specified worksheet. Read-only.
public CellRange AllocatedRange { get; }
Property Value
AutoFilters
public AutoFiltersCollection AutoFilters { get; }
Property Value
CellImages
Cell image array. Read-only.
public ExcelPicture[] CellImages { get; }
Property Value
Cells
Returns all used cells in the worksheet. Read-only.
public CellRange[] Cells { get; }
Property Value
Charts
Returns charts collection. Read-only.
public WorksheetChartsCollection Charts { get; }
Property Value
Columns
Rrepresents all used columns on the specified worksheet. Read-only Range object.
public CellRange[] Columns { get; }
Property Value
Comments
Returns comments collection for this worksheet. Read-only.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding comments to a cell.
ICommentShape comment1 = worksheet.Range["A1"].AddComment();
ICommentShape comment2 = worksheet.Range["B1"].AddComment();
//Set comment text
comment1.Text = "Comment1";
comment2.Text = "Comment2";
//Check count
Console.Write(worksheet.Comments.Count);
//Save to file
workbook.SaveToFile("Comments.xlsx");
public CommentsCollection Comments { get; }
Property Value
HPageBreaks
Returns an HPageBreaks collection that represents the horizontal page breaks on the sheet.
public HPageBreaksCollection HPageBreaks { get; }
Property Value
HyperLinks
Collection of all worksheet's hyperlinks.
public HyperLinksCollection HyperLinks { get; }
Property Value
this[int, int]
Get cell range.
public CellRange this[int row, int column] { get; }
Parameters
Property Value
this[int, int, int, int]
Get cell range.
public CellRange this[int row, int column, int lastRow, int lastColumn] { get; }
Parameters
Property Value
this[string]
Get cell range.
public CellRange this[string name] { get; }
Parameters
name
string
Property Value
MergedCells
Returns all merged ranges. Read-only.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Merge cells
worksheet["C2:D2"].Merge();
worksheet["F3:G3"].Merge();
//Get merged ranges
IXLSRange[] mergedRanges = worksheet.MergedCells;
//Get merged range count . Output will be 2
Console.Write(mergedRanges.Length);
//Save to file
workbook.SaveToFile("MergedCells.xlsx");
public CellRange[] MergedCells { get; }
Property Value
PageSetup
Returns a PageSetup object that contains all the page setup settings for the specified object. Read-only.
public PageSetup PageSetup { get; }
Property Value
ParentWorkbook
public Workbook ParentWorkbook { get; }
Property Value
Pictures
Pictures collection. Read-only.
public PicturesCollection Pictures { get; }
Property Value
PrintRange
Print area of worksheet.
public CellRange PrintRange { get; }
Property Value
QueryTables
public QueryTableCollection QueryTables { get; }
Property Value
Range
Returns a Range object that represents the used range on the
specified worksheet. Read-only.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["B2"].Text = "Text";
//Set Color
worksheet["J3"].Style.Color = Color.Red;
//Get used range . Output will be B2:J3
Console.Write(worksheet.Range.RangeAddressLocal);
//Save to file
workbook.SaveToFile("UsedRange.xlsx");
public CellRange Range { get; }
Property Value
Rows
Represents all the rows on the specified worksheet. Read-only Range object.
public CellRange[] Rows { get; }
Property Value
VPageBreaks
Returns a VPageBreaks collection that represents the vertical page breaks on the sheet. Read-only.
public VPageBreaksCollection VPageBreaks { get; }
Property Value
Workbook
public Workbook Workbook { get; }
Property Value
Methods
ApplyStyle(CellStyle)
Apply style to whole sheet.
public void ApplyStyle(CellStyle style)
Parameters
style
CellStylestyle to apply
CalculateAndGetRowHeight(int)
public double CalculateAndGetRowHeight(int rowIndex)
Parameters
rowIndex
int
Returns
Copy(CellRange, CellRange)
Copys data from a source range to a destination range.
public void Copy(CellRange sourceRange, CellRange destRange)
Parameters
Copy(CellRange, CellRange, CopyRangeOptions)
Copys data from a source range to a destination range.
public void Copy(CellRange sourceRange, CellRange destRange, CopyRangeOptions copyOptions)
Parameters
sourceRange
CellRangeSource range.
destRange
CellRangeDestination range
copyOptions
CopyRangeOptionsCopy options.
Copy(CellRange, CellRange, bool)
Copys data from a source range to a destination range.
public void Copy(CellRange sourceRange, CellRange destRange, bool copyStyle)
Parameters
sourceRange
CellRangeSource range.
destRange
CellRangeDestination range.
copyStyle
boolIndicates whether copys styles.
Copy(CellRange, CellRange, bool, bool, bool)
Copys data from a source range to a destination range.
public void Copy(CellRange sourceRange, CellRange destRange, bool copyStyle, bool updateReference, bool ignoreSize)
Parameters
sourceRange
CellRangeSource range.
destRange
CellRangeDestination range
copyStyle
boolIndicates whether copy styles.
updateReference
boolIndicates whether update reference ranges.
ignoreSize
boolIndicates whether check range sizes.
Copy(CellRange, CellRange, bool, bool, bool, bool)
Copys data from a source range to a destination range.
public void Copy(CellRange sourceRange, CellRange destRange, bool copyStyle, bool updateReference, bool ignoreSize, bool copyShape)
Parameters
sourceRange
CellRangeSource range.
destRange
CellRangeDestination range
copyStyle
boolIndicates whether copy styles.
updateReference
boolIndicates whether update reference ranges.
ignoreSize
boolIndicates whether check range sizes.
copyShape
boolIndicates whether copy shape.
Copy(CellRange, Worksheet, int, int)
Copy data from source range to destination worksheet.
public void Copy(CellRange sourceRange, Worksheet worksheet, int destRow, int destColumn)
Parameters
sourceRange
CellRangeSource range.
worksheet
WorksheetDestination worksheet
destRow
intRow index of destination worksheet.
destColumn
intColumn index of destination worksheet.
Copy(CellRange, Worksheet, int, int, bool)
Copy data from source range to destination worksheet.
public void Copy(CellRange sourceRange, Worksheet worksheet, int destRow, int destColumn, bool copyStyle)
Parameters
sourceRange
CellRangeSource range
worksheet
WorksheetDestination worksheet.
destRow
intRow index of destination worksheet.
destColumn
intColumn index of destination worksheet.
copyStyle
boolIndicates whehter copy styles.
Copy(CellRange, Worksheet, int, int, bool, bool)
Copy data from source range to destination worksheet.
public void Copy(CellRange sourceRange, Worksheet worksheet, int destRow, int destColumn, bool copyStyle, bool updateRerence)
Parameters
sourceRange
CellRangeSource range
worksheet
WorksheetDestination worksheet.
destRow
intRow index of destination worksheet.
destColumn
intColumn index of destination worksheet.
copyStyle
boolIndicates whehter copy styles.
updateRerence
boolIndicates whether update reference range.
CopyColumn(CellRange, Worksheet, int, CopyRangeOptions)
Copys data from a source column to a destination column.
public void CopyColumn(CellRange sourceColumn, Worksheet destSheet, int destColIndex, CopyRangeOptions copyOptions)
Parameters
sourceColumn
CellRangeSource column.
destSheet
WorksheetDestination sheet
destColIndex
intDestination column index
copyOptions
CopyRangeOptionsCopy options.
CopyFrom(Worksheet)
Copy data from specified worksheet.
public void CopyFrom(Worksheet worksheet)
Parameters
worksheet
Worksheetworksheet object
CopyRow(CellRange, Worksheet, int, CopyRangeOptions)
Copys data from a source row to a destination row.
public void CopyRow(CellRange sourceRow, Worksheet destSheet, int destRowIndex, CopyRangeOptions copyOptions)
Parameters
sourceRow
CellRangeSource row.
destSheet
WorksheetDestination sheet
destRowIndex
intDestination row index
copyOptions
CopyRangeOptionsCopy options.
ExportDataTable(CellRange, ExportTableOptions)
public DataTable ExportDataTable(CellRange range, ExportTableOptions options)
Parameters
range
CellRangeoptions
ExportTableOptions
Returns
ExportDataTable(CellRange, bool)
Exports worksheet data into a DataTable.
public DataTable ExportDataTable(CellRange range, bool exportColumnNames)
Parameters
Returns
- DataTable
exported datatable
ExportDataTable(CellRange, bool, bool)
Exports worksheet data into a DataTable.
public DataTable ExportDataTable(CellRange range, bool exportColumnNames, bool computedFormulaValue)
Parameters
range
CellRangeRange to export.
exportColumnNames
boolIndicates if export column name.
computedFormulaValue
boolIndicates wheter compute formula value.
Returns
- DataTable
exported datatable
ExportDataTable(int, int, int, int, ExportTableOptions)
public DataTable ExportDataTable(int firstRow, int firstColumn, int maxRows, int maxColumns, ExportTableOptions options)
Parameters
firstRow
intfirstColumn
intmaxRows
intmaxColumns
intoptions
ExportTableOptions
Returns
ExportDataTable(int, int, int, int, bool)
Exports worksheet data into a DataTable
public DataTable ExportDataTable(int firstRow, int firstColumn, int maxRows, int maxColumns, bool exportColumnNames)
Parameters
firstRow
intRow of first cell.
firstColumn
intColumn of first cell.
maxRows
intMaximun rows to export.
maxColumns
intMaximun columns to export.
exportColumnNames
boolIndicates if export column name.
Returns
- DataTable
Exported datatable.
FindAll(string, FindType, ExcelFindOptions)
Finds the all cells with specified string value.
public CellRange[] FindAll(string findValue, FindType flags, ExcelFindOptions findOptions)
Parameters
findValue
stringValue to search.
flags
FindTypeType of value to search.
findOptions
ExcelFindOptionsWay to search.
Returns
- CellRange[]
All found cells, or Null if value was not found.
FindAllBool(bool)
Finds the cell with the input bool.
public CellRange[] FindAllBool(bool boolValue)
Parameters
boolValue
boolBool value to search for.
Returns
- CellRange[]
Found ranges.
FindAllDateTime(DateTime)
Finds the cell with the input date time.
public CellRange[] FindAllDateTime(DateTime dateTimeValue)
Parameters
dateTimeValue
DateTimeDatetime value to search for.
Returns
- CellRange[]
Found ranges.
FindAllNumber(double, bool)
Finds the cell with the input number.
public CellRange[] FindAllNumber(double doubleValue, bool formulaValue)
Parameters
doubleValue
doubleDouble value to search for.
formulaValue
boolIndicates if includes formula value.
Returns
- CellRange[]
Found ranges.
FindAllString(string, bool, bool)
Finds the cell with the input string.
public CellRange[] FindAllString(string stringValue, bool formula, bool formulaValue)
Parameters
stringValue
stringString value to search for.
formula
boolIndicates if includes formula.
formulaValue
boolIndicates if includes formula value.
Returns
- CellRange[]
Found ranges.
FindAllTimeSpan(TimeSpan)
Finds the cell with the input time span.
public CellRange[] FindAllTimeSpan(TimeSpan timeSpanValue)
Parameters
timeSpanValue
TimeSpanTime span value to search for.
Returns
- CellRange[]
Found ranges.
FindBool(bool)
Finds the cell with the input bool.
public CellRange FindBool(bool boolValue)
Parameters
boolValue
boolBool value to search for.
Returns
- CellRange
Found range.
FindDateTime(DateTime)
Finds the cell with the input date time.
public CellRange FindDateTime(DateTime dateTimeValue)
Parameters
dateTimeValue
DateTimeDateTime value to search for.
Returns
- CellRange
Found range.
FindNumber(double, bool)
Finds the cell with the input double.
public CellRange FindNumber(double doubleValue, bool formulaValue)
Parameters
doubleValue
doubleDouble value to search for.
formulaValue
boolIndicates if includes formula value.
Returns
- CellRange
Found range.
FindString(string, bool, bool)
Finds the cell with the input string.
public CellRange FindString(string stringValue, bool formula, bool formulaValue)
Parameters
stringValue
stringString value to search for.
formula
boolIndicates whether includes formula.
formulaValue
boolIndicates whether includes formula value.
Returns
- CellRange
Found range.
FindTimeSpan(TimeSpan)
Finds the cell with the input time span.
public CellRange FindTimeSpan(TimeSpan timeSpanValue)
Parameters
timeSpanValue
TimeSpanTime span value to search for.
Returns
- CellRange
Found range.
FreezePanes(int, int)
Freezes panes at the specified cell in the worksheet.
public void FreezePanes(int rowIndex, int columnIndex)
Parameters
GetDefaultColumnStyle(int)
Returns default column style.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Create style
CellStyle style = workbook.Styles.Add("CustomStyle");
//Set Color
style.Color = Color.Red;
//Set default style
worksheet.SetDefaultColumnStyle(2,style);
//Get default style
CellStyle defaultStyle = worksheet.GetDefaultColumnStyle(2);
//Set color
defaultStyle.Color = Color.Blue;
worksheet.SetDefaultColumnStyle(3, defaultStyle);
//Save to file
workbook.SaveToFile("GetDefaultColumnStyle.xlsx");
public CellStyle GetDefaultColumnStyle(int columnIndex)
Parameters
columnIndex
intColumn index.
Returns
- CellStyle
Default column style or null if default style is not exists.
GetDefaultRowStyle(int)
Returns default row style.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Create style
CellStyle style = workbook.Styles.Add("CustomStyle");
//Set Color
style.Color = Color.Red;
//Set default style
worksheet.SetDefaultRowStyle(2,style);
//Get default style
CellStyle defaultStyle = worksheet.GetDefaultRowStyle(2);
//Set color
defaultStyle.Color = Color.Blue;
worksheet.SetDefaultRowStyle(3, defaultStyle);
//Save to file
workbook.SaveToFile("GetDefaultColumnStyle.xlsx");
public CellStyle GetDefaultRowStyle(int rowIndex)
Parameters
rowIndex
intRow index.
Returns
- CellStyle
Default row style or null if default style is not set.
GetFreezePanes(out int, out int)
Get Freezes panes cell's index in the worksheet.
public void GetFreezePanes(out int rowIndex, out int columnIndex)
Parameters
rowIndex
intRow index. 0 means no freeze row
columnIndex
intColumn index. 0 means no freeze column
GetIntersectRanges(CellRange, CellRange)
Intersects two ranges.
public CellRange GetIntersectRanges(CellRange range1, CellRange range2)
Parameters
Returns
- CellRange
Intersection of two ranges
Merge(CellRange, CellRange)
Combines a range of cells into a single cell.
public CellRange Merge(CellRange range1, CellRange range2)
Parameters
Returns
- CellRange
Merged ranges
Move(CellRange, CellRange)
Move data from source range to destination range.
public void Move(CellRange sourceRange, CellRange destRange)
Parameters
Move(CellRange, CellRange, bool, bool)
public void Move(CellRange sourceRange, CellRange destRange, bool updateReference, bool copyStyle)
Parameters
OnDispose()
Method which can be overriden by users to take any specific actions when object is disposed.
protected override void OnDispose()
RemoveMergedCells(CellRange)
public void RemoveMergedCells(CellRange range)
Parameters
range
CellRange
RemovePicture(IPictureShape)
Remove picture from this worksheet.
public void RemovePicture(IPictureShape picture)
Parameters
picture
IPictureShapeA pictureshape
RemovePicture(int)
Remove picture from this worksheet.
public void RemovePicture(int index)
Parameters
index
intPicture ID
RemovePicture(string)
Remove picture from this worksheet.
public void RemovePicture(string picturename)
Parameters
picturename
stringPicture name
RemoveRange(CellRange)
Removes range from list.
public void RemoveRange(CellRange range)
Parameters
range
CellRangeSpecified range.
RemoveRange(int, int)
Removes range from list.
public void RemoveRange(int rowIndex, int columnIndex)
Parameters
SetActiveCell(CellRange)
Sets active cell
public void SetActiveCell(CellRange range)
Parameters
range
CellRangeCell to activate.
SetDefaultColumnStyle(int, CellStyle)
Sets default style for column.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Create style
CellStyle style = workbook.Styles.Add("CustomStyle");
//Set Color
style.Color = Color.Red;
//Set default style
worksheet.SetDefaultColumnStyle(2, style);
//Save to file
workbook.SaveToFile("SetDefaultColumnStyle.xlsx");
public void SetDefaultColumnStyle(int columnIndex, CellStyle defaultStyle)
Parameters
SetDefaultColumnStyle(int, int, CellStyle)
Sets default style for column.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Create style
CellStyle style = workbook.Styles.Add("CustomStyle");
//Set Color
style.Color = Color.Red;
//Set default style
worksheet.SetDefaultColumnStyle(2, 5, style);
//Save to file
workbook.SaveToFile("SetDefaultColumnStyle.xlsx");
public void SetDefaultColumnStyle(int firstColumnIndex, int lastColumnIndex, CellStyle defaultStyle)
Parameters
firstColumnIndex
intFirst column index.
lastColumnIndex
intLast column index.
defaultStyle
CellStyleDefault style.
SetDefaultRowStyle(int, CellStyle)
Sets default style for row.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Create style
CellStyle style = workbook.Styles.Add("CustomStyle");
//Set Color
style.Color = Color.Red;
//Set default style
worksheet.SetDefaultRowStyle(2, style);
//Save to file
workbook.SaveToFile("SetDefaultRowStyle.xlsx");
public void SetDefaultRowStyle(int rowIndex, CellStyle defaultStyle)
Parameters
SetDefaultRowStyle(int, int, CellStyle)
Sets default style for row.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Create style
CellStyle style = workbook.Styles.Add("CustomStyle");
//Set Color
style.Color = Color.Red;
//Set default style
worksheet.SetDefaultRowStyle(2, 5, style);
//Save to file
workbook.SaveToFile("SetDefaultRowStyle.xlsx");
public void SetDefaultRowStyle(int firstRowIndex, int lastRowIndex, CellStyle defaultStyle)