Workbook Class

Represents a workbook in a spreadsheet.

Inheritance

Object

Documents.Spreadsheet.Workbook

Namespace: Radzen.Documents.Spreadsheet

Assembly: Radzen.Blazor.dll

Syntax

public class Workbook

Constructors

Workbooklink

Initializes a new instance of the Workbook class.

Declaration
public Workbook()

Properties

Protectionlink

Gets or sets the workbook protection settings.

Declaration
public Documents.Spreadsheet.WorkbookProtection Protection { get; set; }
Property Value
Type Description
Documents.Spreadsheet.WorkbookProtectionGets or sets the workbook protection settings.

Sheetslink

Gets the collection of sheets in the workbook.

Declaration
public IReadOnlyList<Documents.Spreadsheet.Worksheet> Sheets { get; }
Property Value
Type Description
IReadOnlyList<Documents.Spreadsheet.Worksheet>Gets the collection of sheets in the workbook.

Methods

AddSheetlink

Adds a new sheet to the workbook with the specified name, rows, and columns.

Declaration
public Documents.Spreadsheet.Worksheet AddSheet(string name, int rows, int columns)
Parameters
Type Name Description
string name
int rows
int columns
Returns

AddSheetlink

Adds a new sheet to the workbook with the specified name, rows, and columns.

Declaration
public void AddSheet(Documents.Spreadsheet.Worksheet sheet)
Parameters
Type Name Description
Documents.Spreadsheet.Worksheet sheet

GetSheetlink

Gets the sheet with the specified name or null if not found.

Declaration
public Documents.Spreadsheet.Worksheet GetSheet(string name)
Parameters
Type Name Description
string name
Returns

IndexOflink

Gets the index of the specified sheet in the workbook.

Declaration
public int IndexOf(Documents.Spreadsheet.Worksheet sheet)
Parameters
Type Name Description
Documents.Spreadsheet.Worksheet sheet The sheet to find.
Returns
Type Description
intThe zero-based index of the sheet, or -1 if not found.

LoadFromCsvlink

Loads a CSV stream into a new Workbook with a single sheet.

Declaration
public static Documents.Spreadsheet.Workbook LoadFromCsv(IO.Stream stream, Documents.Spreadsheet.CsvImportOptions options)
Parameters
Type Name Description
IO.Stream stream Source stream.
Documents.Spreadsheet.CsvImportOptions options CSV options. When null, defaults are used.
Returns

LoadFromStreamlink

Loads a workbook from the specified stream in the Open XML Spreadsheet format (XLSX).

Declaration
public static Documents.Spreadsheet.Workbook LoadFromStream(IO.Stream stream)
Parameters
Type Name Description
IO.Stream stream
Returns

MoveSheetlink

Moves a sheet from one position to another.

Declaration
public void MoveSheet(int fromIndex, int toIndex)
Parameters
Type Name Description
int fromIndex The current index of the sheet.
int toIndex The target index for the sheet.

RemoveSheetlink

Removes a sheet from the workbook.

Declaration
public bool RemoveSheet(Documents.Spreadsheet.Worksheet sheet)
Parameters
Type Name Description
Documents.Spreadsheet.Worksheet sheet The sheet to remove.
Returns
Type Description
booltrue if the sheet was removed; otherwise false.

SaveAsCsvlink

Saves a single sheet of the workbook to the specified stream in CSV format. By default the first sheet is exported; pass Sheet to choose a different one. CSV is single-sheet by design, matching Excel's "Save As CSV" behavior.

Declaration
public void SaveAsCsv(IO.Stream stream, Documents.Spreadsheet.CsvExportOptions options)
Parameters
Type Name Description
IO.Stream stream Destination stream.
Documents.Spreadsheet.CsvExportOptions options CSV options. When null, defaults are used (comma separator, UTF-8 with BOM, CRLF line endings, RFC 4180 minimal quoting).

SaveToStreamlink

Saves the workbook to the specified stream in the Open XML Spreadsheet format (XLSX).

Declaration
public void SaveToStream(IO.Stream stream)
Parameters
Type Name Description
IO.Stream stream
An error has occurred. This app may no longer respond until reloaded. Reload 🗙