Apodemus.NPOI.WordTemplateMapper 1.0.2

dotnet add package Apodemus.NPOI.WordTemplateMapper --version 1.0.2
NuGet\Install-Package Apodemus.NPOI.WordTemplateMapper -Version 1.0.2
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="Apodemus.NPOI.WordTemplateMapper" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Apodemus.NPOI.WordTemplateMapper --version 1.0.2
#r "nuget: Apodemus.NPOI.WordTemplateMapper, 1.0.2"
#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.
// Install Apodemus.NPOI.WordTemplateMapper as a Cake Addin
#addin nuget:?package=Apodemus.NPOI.WordTemplateMapper&version=1.0.2

// Install Apodemus.NPOI.WordTemplateMapper as a Cake Tool
#tool nuget:?package=Apodemus.NPOI.WordTemplateMapper&version=1.0.2

NPOI.WordTemplateMapper

This is a Word document mapper which can map a disctionary of objects to a document.

usage

Example usage

using NPOI.WordTemplateMapper.XWPF;
using NPOI.XWPF.UserModel;

// Assemble the data
List<object> theList = new() {
    new { A = "Chirp", B = "Meow", C = "Woof", D = "Moo", E = "Bonjour", F = "Quack"},
    new { A = "Monday", B = "Tuesday", C = "Wednesday", D = "Thursday", E = "Friday", F = "Saturday"},
    new { A = "Red", B = "Green", C = "Blue", D = "Yellow", E = "Magenta", F = "Cyan"},
    new { A = "Belgium", B = "Denmark", C = "Spain", D = "Austria", E = "Monaco", F = "Angola"},
    new { A = PokeType.Water, B = PokeType.Grass, C = PokeType.Fire, D = PokeType.Ghost, E = PokeType.Electric, F = PokeType.Fighting},
};
Dictionary<string, object> data = new()
{
    { "{{List}}", theList },
    { "{{CoolSinger}}", "Rick Astley" },
    { "{{ListTotal}}", 42069 },
    { "{{Pokemon}}", new { Name = "Pikachu", PokeType = PokeType.Electric } },
    { "{{Phone}}", new { Brand = new { Name = "Huawei"}, Model = "Mate 50 Pro" } },
    { "{{Actions}}", new string[] { "give you up", "let you down", "run around and desert you" } },
    { "{{Wow}}", new Array[] { new object[] { new { Yay = "waaaa" } } } }
};

// Get the Document
string template = @"A.docx";
using FileStream fileStream = File.OpenRead(template);
XWPFDocument document = new(fileStream);

// Map document
XWPFDocumentMapper documentMapper = new();

documentMapper.MapDocument(document, data);

// Create new document
string generateFile = @"output.docx";
using FileStream outputStream = File.Create(generateFile);
document.Write(outputStream);

Mapping

Mapping keys must start and end with non alphanumeric characters, preferebly {{two accolades like these}}.

Mapping table rows

Add your key to the title of the table. This can be accessed under "Table Properties" in Microsoft Word. This key will be cleaned up during mapping, so won't need to worry about accessibility.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 is compatible.  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 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. 
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
1.0.2 102 4/12/2024
1.0.1 80 4/12/2024
1.0.0 265 12/16/2022