Universal.Common.Formats.Docx 1.2.0

dotnet add package Universal.Common.Formats.Docx --version 1.2.0
                    
NuGet\Install-Package Universal.Common.Formats.Docx -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Universal.Common.Formats.Docx" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Universal.Common.Formats.Docx" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Universal.Common.Formats.Docx" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Universal.Common.Formats.Docx --version 1.2.0
                    
#r "nuget: Universal.Common.Formats.Docx, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Universal.Common.Formats.Docx@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Universal.Common.Formats.Docx&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Universal.Common.Formats.Docx&version=1.2.0
                    
Install as a Cake Tool

Universal.Common.Formats.Docx

Reads and writes .docx WordprocessingML packages.

Quick start

using Universal.Common.Formats.Docx;

using WordDocument document = WordDocument.Open("report.docx");
Console.WriteLine(document.Text);

Create a formatted document

using Universal.Common.Formats.Docx;
using Universal.Common.Formats.Docx.Authoring;
using Universal.Common.Formats.Docx.Blocks;
using Universal.Common.Formats.Docx.Styles;

using WordprocessingDocument document = WordprocessingDocument.Create();
document.ApplyBatch(working =>
{
    DocumentPageLayout page = DocumentPageLayout.A4();
    page.MarginLeftPoints = page.MarginRightPoints = 36;
    page.MarginTopPoints = page.MarginBottomPoints = 36;
    working.SetPageLayout(page);
    working.SetDocumentDefaults(
        paragraph: new DocumentParagraphOptions { SpacingAfterPoints = 6, LineSpacing = 1.1 },
        text: new DocumentTextStyle { FontFamily = "Arial", FontSizePoints = 11, Color = "222222" });
    working.DefineStyle(new DocumentStyleDefinition
    {
        Id = "ReferralHeading", Name = "Referral heading", BasedOnStyleId = "Heading1",
        Paragraph = new DocumentParagraphOptions { KeepNext = true, KeepLines = true },
        Text = new DocumentTextStyle { FontSizePoints = 16, Bold = true }
    });
    working.AddParagraph("Referral", "ReferralHeading");
    DocumentTableReference table = working.AddTable(new[]
    {
        new[] { "Capability", "Details" },
        new[] { "Layout", "Readable descriptions in a full-width table." }
    }, new DocumentTableOptions
    {
        WidthPercent = 100, ColumnWidthsPoints = new[] { 120d, 403.3d },
        FixedLayout = true, HeaderRowCount = 1, CannotSplitRows = true,
        CellMargins = new DocumentCellMargins { LeftPoints = 6, RightPoints = 6, TopPoints = 4, BottomPoints = 4 }
    });
    working.SetTableCellFormatting(new DocumentTableCellReference(table, 0, 0),
        new DocumentTableCellOptions { ShadingColor = "DDEEFF", VerticalAlignment = TableCellVerticalAlignment.Center });
    working.SetDefaultFooter(new[]
    {
        DocumentTextElement.TextRun("Page "), DocumentTextElement.Field("PAGE", "1"),
        DocumentTextElement.TextRun(" of "), DocumentTextElement.Field("NUMPAGES", "1")
    });
});
document.Save("referral.docx");

All page dimensions, table grid widths, cell margins, row heights and border widths use points. WidthPercent uses ordinary percentages (100 means the available section-column width), not OOXML's fiftieths of a percent. Set either WidthPoints or WidthPercent. If ColumnWidthsPoints is supplied together with an overall width, its sum must match the effective width within 0.05 points; it is not interpreted as ratios. Supplying column widths alone also sets the overall point width to their sum, replacing a previous automatic/percentage/point width to keep the geometry consistent. Percent widths in multi-column sections use the containing column. For unequal columns, the initial preferred grid uses the first column; the percentage remains relative to the actual containing column during layout.

Existing AddTable(rows) calls retain equal 120-point columns and automatic table width. New documents retain Letter paper and one-inch margins unless configured. No table is automatically expanded to full width. Named table styles can supply alignment, indentation, cell margins and borders. Widths and fixed-layout mode belong to individual tables; named styles reject these settings as well as per-table grid widths and row counts.

AddRichTable accepts DocumentTableRow / DocumentTableCell / DocumentTableParagraph objects, including multiple paragraphs and styled inline elements:

document.AddRichTable(new[]
{
    new DocumentTableRow
    {
        Cells = new[]
        {
            new DocumentTableCell
            {
                Paragraphs = new[]
                {
                    new DocumentTableParagraph
                    {
                        Elements = new[] { DocumentTextElement.Hyperlink("Source title", "https://example.org/source") }
                    }
                }
            }
        }
    }
}, new DocumentTableOptions { WidthPercent = 100 });

Hyperlink writes a real external relationship in the containing body/header/footer story. BookmarkLink creates an internal bookmark link. Field stores the instruction and a cached result; field evaluation depends on the renderer or consuming application. Header/footer setters accept these elements and styled text, including first/even-page variants. AddTableCellParagraph appends content without replacing existing paragraphs.

Formatting existing content

Use GetParagraphs with PatchParagraphFormatting. For precise native run targets, both WordDocument and WordprocessingDocument expose GetNativeRuns() for one traversal of the main story and GetNativeRuns(paragraphIndex) for one paragraph. Each immutable DocumentNativeRunInfo supplies ParagraphIndex, RunIndex, source VisibleText, FieldInstruction, HasFieldMarker, HyperlinkUri, IsHyperlink and IsDeleted. Use those exact indices with PatchRunFormatting; resolved paragraph Inlines/text runs have a different sequence and must not supply native run indices. Field marker/instruction runs and deleted runs retain native ordinals. Paragraph indices include table-cell/content-control paragraphs and exclude text-box/header/footer stories; nested paragraph runs are excluded from their enclosing run sequence. The no-argument discovery overload avoids reparsing a document for every paragraph. These formatting patches retain text, hyperlinks, fields, bookmarks and surrounding markup.

GetTables, GetTableRows and GetTableCells expose references for SetTableFormatting, SetTableRowFormatting and SetTableCellFormatting. Table indices follow the reader's supported main-document block traversal, including nested tables and content controls and excluding text-box/header/footer stories and unsupported block wrappers. Row and cell indices are physical XML indices; a spanning cell occupies one cell index. Formatting existing tables preserves merge metadata. Resizing a grid updates preferred cell widths, including cells spanning multiple columns; it does not create or remove merges.

Null options retain existing properties, except that supplied column widths alone derive a consistent overall table width. Explicit false turns a flag off; zero margins remain explicit values. Partial margin/border patches retain unspecified edges. DocumentTableBorder.Visible = false suppresses an edge. Paragraph/run patch clearProperties lists use exact C# option property names, such as nameof(DocumentTextStyle.Bold), to remove direct overrides and restore inheritance. Clears happen before supplied values are applied. SetDocumentDefaults accepts corresponding paragraph/run clear lists; DefineStyle accepts Name, BasedOnStyleId, NextStyleId, Paragraph, Text, and Table as clearable groups. Table formatting APIs do not expose generic clear lists.

SetPageLayout(layout, sectionIndex) patches a section; omitting sectionIndex selects the final section. AddSectionBreak starts a new final section and copies existing settings, optionally applying different geometry. Orientation normalizes physical dimensions to portrait/landscape. Standard left gutters are supported; mirrored, top and right-to-left gutter layouts are rejected rather than approximated.

ApplyBatch commits all package parts only after its callback succeeds. Perform every edit through the callback's supplied document; an exception leaves the original document unchanged. Save the original document after success. References remain positional, so rediscover indices after operations that change document structure.

The reader accepts Strict and Transitional OOXML. Authoring accepts Transitional OOXML and rejects Strict packages before editing; convert them with an appropriate Office application first. Formatting patches preserve unspecified source XML, but the API is not a Word layout engine. Pagination and visual checks belong to Universal.Common.Formats.Docx.Rendering; no particular Microsoft Word page count is guaranteed.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Universal.Common.Formats.Docx:

Package Downloads
Universal.Common.Formats.Docx.Rendering

Lays out and renders DOCX documents.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 56 11/20/2026
1.1.2 133 11/18/2026
1.1.1 852 8/22/2026
1.1.0 177 8/21/2026
1.0.0 120 8/21/2026

Add typed table geometry and cell formatting, rich table content and hyperlinks, named styles and document defaults, section page layout, preservation-safe paragraph/run formatting patches, native run/table target discovery, and atomic authoring batches.