Class WorksheetCollection
- Namespace
- SheetStream
- Assembly
- SheetStream.dll
The worksheets of a workbook. Adding a sheet seals the previous one, because the package streams one sheet at a time straight into the zip archive.
public sealed class WorksheetCollection : IReadOnlyList<Worksheet>, IReadOnlyCollection<Worksheet>, IEnumerable<Worksheet>, IEnumerable
- Inheritance
-
WorksheetCollection
- Implements
- Inherited Members
Properties
Count
Gets the number of elements in the collection.
public int Count { get; }
Property Value
- int
The number of elements in the collection.
Current
The sheet currently accepting rows, or null before the first sheet is added.
public Worksheet? Current { get; }
Property Value
this[int]
Gets the element at the specified index in the read-only list.
public Worksheet this[int index] { get; }
Parameters
indexintThe zero-based index of the element to get.
Property Value
- Worksheet
The element at the specified index in the read-only list.
Methods
Add(string)
Adds a worksheet and makes it the current one. The previously current sheet is sealed and can no longer receive rows.
public Worksheet Add(string name)
Parameters
namestringTab name: 1 to 31 characters, unique within the workbook (case-insensitive), without any of
: \ / ? * [ ], and not starting or ending with an apostrophe.
Returns
Edit(int)
Opens a sheet for editing by its zero-based position in the workbook's tab order. See Edit(string).
public Worksheet Edit(int index)
Parameters
indexint
Returns
Edit(string)
Opens a sheet of the workbook being edited with every existing cell loaded into Cells
(edit mode), and makes it the current one; the previously current sheet is sealed. Read values with
sheet.Cells["B2"].Value, change them, add rows below sheet.Cells.Dimension.LastRow, and
Save() writes the whole sheet back. Cells you do not touch are written exactly
as they were; sheets you do not open are copied unchanged. Meant for small workbooks: a sheet with
more than MaxEditableCells cells is refused.
public Worksheet Edit(string name)
Parameters
namestringThe sheet's tab name (case-insensitive).
Returns
Examples
using var package = ExcelPackage.Edit("budget.xlsx");
var sheet = package.Workbook.Worksheets.Edit("Q4");
sheet.Cells["B4"].Value = 1250;
package.Save();
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<Worksheet> GetEnumerator()
Returns
- IEnumerator<Worksheet>
An enumerator that can be used to iterate through the collection.
Open(string)
Opens a sheet of the template for filling (template mode only) and makes it the current one; the previously current sheet is sealed. Sheets you do not open are copied unchanged.
public Worksheet Open(string name)
Parameters
namestringThe sheet's tab name in the template (case-insensitive).