Table of Contents

Class XlsxFormula

Namespace
DocToolkit
Assembly
DocToolkit.Xlsx.dll

A cell value meaning "this cell holds a formula". Use it anywhere a cell value is accepted — inside XlsxSheet rows, inside rows passed to AppendRows(byte[], string, IEnumerable<IEnumerable<object?>>), or as the value argument to SetCell(byte[], string, string, object?).

No cached result is written. The file carries the formula and nothing else. Excel recalculates when it opens the file, and this package's own readers (ReadCell(byte[], string, string), ReadSheet(byte[], string)) compute the value on read — but a third-party reader that only reads cached values, such as openpyxl with data_only=True, sees an empty cell until Excel has opened and saved the file.

This package's own XlsxToPdfConverter used to be exactly such a reader — its renderer reads the raw cell rather than going through ClosedXML's lazy evaluation, so a formula cell rendered its own source text where the value belonged, found 2026-08-31. It now calculates before rendering, so this is no longer a caveat for it specifically. It remains one for anything else that reads this package's output: use EvaluateFormulas(byte[]) to write the computed value into the file itself before handing it to a reader that will not recalculate on its own, and InspectFormulas(byte[]) to find out first whether the engine understands a given formula well enough to trust its value.

A formula that cannot be evaluated reads back as its Excel error string — #DIV/0!, #NAME?, #REF! — rather than throwing, which is what Excel itself shows.

public sealed class XlsxFormula
Inheritance
XlsxFormula
Inherited Members

Properties

Formula

The formula, without a leading =, which is how the file stores it.

public string Formula { get; }

Property Value

string

Methods

From(string)

Creates a formula cell value. A leading = is optional and is stripped: the file format stores formulas without it, and accepting both spellings stops the value that round-trips from differing from the one that was written.

public static XlsxFormula From(string formula)

Parameters

formula string

Returns

XlsxFormula

Exceptions

ArgumentNullException

formula is null.

ArgumentException

formula is empty, whitespace, or just "=".