Avalonia.Controls.Documents.Serialization.Docx
12.2.0
Prefix Reserved
dotnet add package Avalonia.Controls.Documents.Serialization.Docx --version 12.2.0
NuGet\Install-Package Avalonia.Controls.Documents.Serialization.Docx -Version 12.2.0
<PackageReference Include="Avalonia.Controls.Documents.Serialization.Docx" Version="12.2.0" />
<PackageVersion Include="Avalonia.Controls.Documents.Serialization.Docx" Version="12.2.0" />
<PackageReference Include="Avalonia.Controls.Documents.Serialization.Docx" />
paket add Avalonia.Controls.Documents.Serialization.Docx --version 12.2.0
#r "nuget: Avalonia.Controls.Documents.Serialization.Docx, 12.2.0"
#:package Avalonia.Controls.Documents.Serialization.Docx@12.2.0
#addin nuget:?package=Avalonia.Controls.Documents.Serialization.Docx&version=12.2.0
#tool nuget:?package=Avalonia.Controls.Documents.Serialization.Docx&version=12.2.0
Avalonia.Controls.Documents.Docx
DOCX (Open XML) serialization support for Avalonia.Controls.Documents. Enables reading and writing FlowDocument content in the DOCX format.
Features
- Import DOCX files into a FlowDocument
- Export FlowDocument content to DOCX format
- Implements the
IDocumentSerializerinterface
Quick Start
// Read a DOCX file
var serializer = new DocxSerializer();
var document = serializer.Deserialize(stream);
// Write a DOCX file
serializer.Serialize(document, outputStream);
Dependencies
Avalonia.Controls.Documents
Documentation
See the documentation for more details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Avalonia.Controls.Documents (>= 12.2.0)
- AvaloniaUI.Licensing (>= 3.1.1)
- DocumentFormat.OpenXml (>= 3.4.1)
-
net8.0
- Avalonia.Controls.Documents (>= 12.2.0)
- AvaloniaUI.Licensing (>= 3.1.1)
- DocumentFormat.OpenXml (>= 3.4.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
## 12.2.0
### Features
- Inline image round-trip: reads/writes DrawingML `w:drawing/wp:inline` images backed by `word/media/` parts. Identical payloads share one media part; PNG/JPEG/GIF/BMP/TIFF are written; floating `wp:anchor` images are imported as inline (best effort). Honors `DocumentSerializerOptions.MaxImageBytes`.
### Fixes
- Table cells now keep their padding. Word stores the cell inset (`w:tblCellMar`) on the built-in `TableNormal` style, and a document's table style reaches it through `w:basedOn` - Word's own `TableGrid` declares only borders. The table-style lookup inspected the applied style alone, so it found no margins and every cell in the table lost its padding. Table-style lookups now walk the `basedOn` chain for the cell margins, while a style that declares its own still wins.
- An empty paragraph's character formatting now round-trips through the paragraph mark's run properties (`w:pPr/w:rPr`), the state the editor leaves behind when all content of a formatted paragraph is deleted. The writer emits the mark for empty body and table-cell paragraphs, and the reader lifts it onto the paragraph element only when the paragraph has no content, since with runs present the mark formatting belongs to the mark alone and lifting it would re-style unformatted runs. Font sizes quantize to half points, the same precision run sizes have.
- Table interior gridlines (Word's `w:insideH` / `w:insideV`) are now imported, so a bordered table renders its grid instead of only a faint editor shade. The interior grid — from either direct `tblBorders` or the table style (such as "Table Grid") — is carried on the table and drawn once as a whole grid rather than distributed onto the cells. Each gridline is resolved from the two cells that meet at it, a cell's own `w:tcBorders` side winning over the grid, so a cell with a border on only one side (a purple bottom, say) keeps the black grid on its other sides. Strokes are centred on the gridline, so adjacent cells no longer double them and the corners join. The writer emits the grid back as `w:insideH` / `w:insideV`, and its placeholder borders (single/auto) are still ignored on read so a plain table round-trips without gaining a grid.
- A table cell's vertical alignment (`w:vAlign` = center / bottom) is now read and applied, so cell content sits where Word places it within the row instead of always at the top. It round-trips through the writer.
- Merged table cells now round-trip. On read, a cell's `w:gridSpan` becomes `TableCell.ColumnSpan` and a `w:vMerge` (a restart cell plus its continuations in the rows below) becomes `TableCell.RowSpan`, with the continuation cells folded into the cell above, so a table with merged columns or rows renders with the merges instead of every following cell shifting and the trailing column dropping. On write, a column span emits `w:gridSpan` and a row span emits a `w:vMerge` restart plus the continuation cells for the rows below, so saving a merged table back to DOCX keeps the merges. Verified on the real customer file: its 7-column table with a column merge and a row merge saves and reloads with the same structure.
- A cell paragraph's spacing now resolves against the table style, matching the OOXML style order (document defaults, then table style, then the paragraph's own style, then direct formatting). A table style that compacts cell spacing — such as the built-in "Table Grid", whose `w:pPr` sets `w:after="0"` and single line spacing — is now honoured, instead of every cell paragraph inheriting the document default's 8pt space-after. That phantom space-after had left a gap under the last line of a cell, most visible in a bottom-aligned cell where it pushed the text off the bottom edge. Deliberate spacing still wins: a paragraph style or direct `w:spacing` on a cell paragraph overrides the table style, so intentional in-cell spacing is preserved.
- Table row heights (`w:trHeight`) are now imported as a row minimum height, so a table keeps Word's row proportions instead of collapsing each row to its content. The writer emits them back (as an "at least" rule). This also lets cell vertical alignment show, since short rows previously left no room to align within.
- List indentation is now imported onto the `List` rather than each item. A numbering level's `w:ind` left indent — taken as the per-level delta from the parent level, so structural nesting accumulates back to Word's absolute indent — becomes the list's content padding, and the hanging becomes `List.MarkerOffset`, so nested lists step by the real indent and the marker hangs like Word. The flat style-resolved left indent is no longer copied onto the item as a margin, which had doubled the indent and pushed deeply nested content off the page. The writer no longer emits a hardcoded 720/360 numbering-indent default, so a synthetic round-trip does not gain phantom padding.
- Text highlight (Word's `w:highlight`) is now imported. A highlighted run renders with its highlight colour — mapped from the fixed highlight palette (yellow, green, cyan, the dark variants, and so on) — instead of the highlight being dropped. The original named value is kept, so a save re-emits `w:highlight` rather than converting it to `w:shd` shading. When a run carries both a highlight and shading, the highlight wins, matching Word. Inline run metadata read from a document (this highlight, the exact half-point font size, theme colour, language, and the specific underline style) now survives a round-trip instead of being discarded on read.
- A run background inherited from a character or paragraph style (`w:shd` or `w:highlight` set on the style rather than the run) is now imported too, so style-driven shading is no longer lost. A background set directly on the run still overrides the style's.
- The numbering marker alignment (`w:lvlJc`) is now imported onto `List.MarkerAlignment`, so a right-aligned level (Word uses this for roman-numeral levels) renders its numbers right-aligned, sharing a right edge with a consistent gap to the text, as Word does.