Table of Contents

Class XlsxDocument

Namespace
DocWright.Formats.Xlsx
Assembly
DocWright.Formats.Xlsx.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

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.

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

AddSheet(string)

Adds an empty worksheet at the end of the workbook.

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?).

Open(Stream, XlsxReadSettings?)

Opens a workbook.

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.