William.DocxTemplateEngine 1.0.1

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package William.DocxTemplateEngine --version 1.0.1
                    
NuGet\Install-Package William.DocxTemplateEngine -Version 1.0.1
                    
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="William.DocxTemplateEngine" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="William.DocxTemplateEngine" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="William.DocxTemplateEngine" />
                    
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 William.DocxTemplateEngine --version 1.0.1
                    
#r "nuget: William.DocxTemplateEngine, 1.0.1"
                    
#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 William.DocxTemplateEngine@1.0.1
                    
#: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=William.DocxTemplateEngine&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=William.DocxTemplateEngine&version=1.0.1
                    
Install as a Cake Tool

William.DocxTemplateEngine

Lightweight DOCX template engine for .NET using TemplateEngine.Docx.


πŸ“¦ Installation

dotnet add package William.DocxTemplateEngine

πŸš€ Quick Start

var engine = new DocxTemplateEngine();

engine.Render(
    "template.docx",
    "output.docx",
    new
    {
        contract_number = "HD001",

        staffs = new[]
        {
            new
            {
                role = "Kα»Ή thuαΊ­t",
                staff_email_vietunion = "tech@abc.com",
                staff_phone_vietunion = "0909000001",
                staff_email_partner = "tech@abc.com",
                staff_phone_partner = "0909000001"
            },
            new
            {
                role = "CSKH",
                staff_email_vietunion = "cs@abc.com",
                staff_phone_vietunion = "0909000002",
                staff_email_partner = "tech@abc.com",
                staff_phone_partner = "0909000001"
            }
        }
    }
);

Render to byte[]

var bytes = engine.RenderToBytes("template.docx", model);

Render from Stream

using var stream = File.OpenRead("template.docx");

var bytes = engine.RenderToBytes(stream, model);

βš™οΈ Options

engine.Render("template.docx", "output.docx", model, removeContentControls: true);
Parameter Description
removeContentControls Remove content controls after rendering (default: true)

πŸ“ Creating Template (Content Controls)

This library uses Word Content Controls, not plain text placeholders.

Enable Developer Tab

  1. Open Microsoft Word
  2. Go to File β†’ Options β†’ Customize Ribbon
  3. Enable Developer

Create a simple field

  1. Go to Developer
  2. Click Plain Text Content Control
  3. Open Properties
  4. Set:

Tag: contract_number


Create a table (repeating data)

  1. Insert a table in Word
  2. In the data row, add Content Controls for each column

Example tags:

  • role
  • staff_email_vietunion
  • staff_phone_vietunion
  • staff_email_partner
  • staff_phone_partner

Repeating Section (Important)

To bind a collection:

  1. Select the entire data row
  2. Click Repeating Section Content Control
  3. Set:

Tag: staffs


Official Documentation

https://learn.microsoft.com/en-us/office/client-developer/word/content-controls-in-word


πŸ“Œ Notes

  • Template must use Content Controls
  • Field names must match model properties
  • Do not use {{variable}} syntax

πŸ“„ License

MIT License Β© 2026 William

Product 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated