Skip to content

Add OpenXmlCellValue for per-cell formulas and styles on export - #1021

Draft
virzak wants to merge 3 commits into
mini-software:masterfrom
virzak:feature/write-cell-values
Draft

virzak wants to merge 3 commits into
mini-software:masterfrom
virzak:feature/write-cell-values

Conversation

@virzak

@virzak virzak commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Exports can only set formulas and number formats for a whole column, and font colors only through the editor after saving. Wrapping a value in OpenXmlCellValue sets a formula, number format or font color for that one cell:

var rows = new[]
{
    new Dictionary<string, object?>
    {
        ["Amount"] = new OpenXmlCellValue(0.25) { NumberFormat = "0.0%", Style = { FontColor = Color.Gray } },
        ["Double"] = new OpenXmlCellValue(0.5) { Formula = "A2*2" }, // 0.5 is written as the cached result
    }
};
await exporter.ExportAsync(stream, rows);
  • Style is the editor's OpenXmlCellStyle (Add deferred cell style updates #1013), so properties added to it later can apply to exported cells too.
  • SheetStyleFormatsCache now keys cell formats by number format and font color, so column formats and cell formats share one set of cellXfs and identical styles are written once. Existing column formats get the same indexes as before.
  • A cell with only a font color keeps the number format it would otherwise have had (the column format, or the date and time defaults).
  • Wrapped values in typed rows use the runtime type of the value, since the property is declared as object.
  • The minimal style builder now applies the existing-workbook numFmt offset to its custom xf entries, matching its numFmt entries.

Wrapping a value sets a formula, number format or font color for that
cell alone. Cell formats now share one cache with column formats, which
also gives the minimal style builder the numFmt offset it lacked when
inserting into an existing workbook.
@coderabbitai

coderabbitai Bot commented Oct 10, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

Shares the style type with the editor, so properties added to it later
apply to exported cells as well.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant