Class XlsxDocument
- Namespace
- DocWright.Spreadsheet
- Assembly
- DocWright.Spreadsheet.dll
An existing workbook, opened to be read and saved back with nothing lost.
public sealed class XlsxDocument
- Inheritance
-
XlsxDocument
- Inherited Members
Remarks
What this is beside XlsxWorkbook. XlsxWorkbook is a workbook a caller builds from its own data and XlsxWriter writes; it holds only what it can write. This type is a workbook somebody else made. It keeps every part of the package as the bytes it was read with - the charts, the pivot tables, the macros, the formulas, everything this library has no model for - and reads from them what it is asked: the sheets, and a cell's value, formula and format.
Saving. Save(Stream, XlsxWriteSettings?) writes those same bytes: every part comes out with the content it went in with, in the order it was in. Nothing is rebuilt from what was read, so nothing the reader does not understand can be lost by it. The ZIP container around the parts is written afresh and deterministically.
Changing cells. A sheet's cells can be given a value, a formula or a look, emptied or removed (SetValue(int, int, XlsxCellValue) and its siblings). A save then differs from the file only where it has to: an edited sheet's part is the text it was with the edited cells replaced, the style part gains a cell format when a new look was used, and the workbook drops its calculation chain and asks for a full calculation. Every other part is still the bytes it was read with.
Formulas are not calculated. A formula cell's Value is the result stored in the file, and stays that after a cell it depends on is changed, until an application that calculates opens the saved workbook.
Untrusted input. The package is read under Limits, with DTDs prohibited and nothing outside the package ever fetched. Malformed input is an InvalidDocumentException, a passed limit a ResourceLimitExceededException.
The whole package is held in memory from Open(Stream, XlsxReadSettings?) on, and the stream it came from is not used again. An instance is not safe for concurrent use; separate instances are independent.
Properties
- CalculatedFunctions
The functions this library calculates, by name, in order.
- DefaultStyle
Gets the look of a cell that states none: the workbook's default font, its size and colour, no fill and no borders. It is what Style gives for a cell with no style of its own.
- IsModified
Gets whether any cell has been changed since the workbook was opened. A change stays a change: setting a cell back to what it was does not undo it, and saving does not reset it.
- IsStructureProtected
Gets whether the workbook's structure is protected (
workbookProtection lockStructure): sheets cannot be added, removed, moved, renamed, hidden or shown in Excel.
- Names
Gets the workbook's defined names, of the workbook and of each sheet, in the order the file lists them: names to add, change and remove, as Excel's Name Manager does.
- Properties
Gets the workbook's core properties (title, subject, author, keywords, comments, category), read from the package's core properties part; every one null for a workbook that has no such part.
- Sheets
Gets the sheets, in the order of the workbook's tabs.
- Uses1904DateSystem
Gets whether the workbook counts dates from 1904 rather than 1900. The same serial number is a different day in each; ToDateTime() allows for it.
Methods
- AddChartSheet(string, XlsxChartType, XlsxDocumentSheet, XlsxCellRange, XlsxChartOptions?)
Adds a chart sheet after the last sheet (Phase 211): one chart filling the sheet, made of a range of another sheet as Add(XlsxChartType, XlsxCellRange, string, XlsxChartOptions?) makes one.
- AddSheet(string)
Adds an empty worksheet at the end of the workbook.
- Calculate(XlsxCalculationOptions?)
Calculates every formula of the workbook's worksheets as Excel does, in the order the formulas read each other, and gives each cell its result, which a save writes with the formula. An array formula fills the range it was entered over, and a dynamic array spills as far as its result reaches (
#SPILL!when a cell it would fill holds something), Phase 210. A formula that uses a function this library does not calculate (CalculatedFunctions) and every formula that reads its cell keep the values the file stores, and are named in the result; so are the cells of a cycle. When everything was calculated and nothing changes after, the saved workbook no longer asks Excel for a full calculation when it is opened.
- CopySheetFrom(XlsxDocumentSheet, string?)
Copies a sheet of another workbook to the end of this one.
- Create(XlsxCreateSettings?)
Starts a workbook from nothing: one empty sheet, the default look, and nothing else.
- FillTemplate(IReadOnlyDictionary<string, object?>, XlsxTemplateOptions?)
Fills the workbook as a template: each block of rows marked
{{#Name}}is repeated once for each item of the listName, with the item's members filled in, and every other placeholder is filled fromdata.
- FindPlaceholderNames(XlsxPlaceholderOptions?)
Lists the placeholders the workbook's text cells hold. See FindPlaceholderNames(XlsxPlaceholderOptions?).
- FindRegex(string, XlsxFindOptions?)
Finds every match of a regular expression in the workbook's worksheets. See FindRegex(string, XlsxFindOptions?).
- FindSheet(string)
Finds a sheet by its name.
- FindText(string, XlsxFindOptions?)
Finds every occurrence of a text in the workbook's worksheets. See FindText(string, XlsxFindOptions?).
- FindWildcards(string, XlsxFindOptions?)
Finds every match of an Excel wildcard pattern in the workbook's worksheets. See FindWildcards(string, XlsxFindOptions?).
- From(XlsxWorkbook)
Carries a generated workbook into the model that opens one, so that it can be read back, searched and edited as an opened workbook is.
- FromCsv(TextReader, XlsxCsvReadOptions?)
Makes a workbook of one sheet from delimited text (CSV).
- FromMarkdownTable(TextReader)
Makes a workbook of one sheet from the first Markdown table in a text.
- Merge(XlsxDocument, XlsxMergeOptions?)
Appends every sheet of another workbook to this one.
- Open(Stream, XlsxReadSettings?)
Opens a workbook.
- ProtectStructure(string?, bool)
Protects the workbook's structure as Excel's Protect Workbook does, with a password hashed as Excel hashes it (SHA-512, a random 16-byte salt, 100,000 spins) or none. A protection the workbook already has is replaced.
- ReplacePlaceholders(IReadOnlyDictionary<string, object?>, XlsxPlaceholderOptions?)
Fills the placeholders in the workbook's text cells from a dictionary. See ReplacePlaceholders(IReadOnlyDictionary<string, object?>, XlsxPlaceholderOptions?).
- ReplaceRegex(string, string, XlsxFindOptions?)
Replaces every match of a regular expression in the workbook's worksheets. See ReplaceRegex(string, string, XlsxFindOptions?).
- ReplaceText(string, string, XlsxFindOptions?)
Replaces every occurrence of a text in the workbook's worksheets. See ReplaceText(string, string, XlsxFindOptions?).
- Save(Stream, XlsxWriteSettings?)
Writes the workbook to a stream.
- ToArray(XlsxWriteSettings?)
Writes the workbook and returns the package bytes.
- ToCsv(string, TextWriter, XlsxCsvOptions?)
Writes one sheet as delimited text (CSV). See ToCsv(TextWriter, XlsxCsvOptions?).
- ToJson(string, Stream, XlsxJsonOptions?)
Writes one sheet as JSON. See ToJson(Stream, XlsxJsonOptions?).
- ToMarkdown(string, TextWriter, XlsxMarkdownOptions?)
Writes one sheet as a Markdown table. See ToMarkdown(TextWriter, XlsxMarkdownOptions?).
- UnprotectStructure(string?)
Removes the workbook's protection, as Excel's Unprotect Workbook does: with the password when it has one. A workbook that is not protected is left as it is.