OpenXmlBinder 1.0.2

dotnet add package OpenXmlBinder --version 1.0.2
                    
NuGet\Install-Package OpenXmlBinder -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="OpenXmlBinder" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenXmlBinder" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="OpenXmlBinder" />
                    
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 OpenXmlBinder --version 1.0.2
                    
#r "nuget: OpenXmlBinder, 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.
#:package OpenXmlBinder@1.0.2
                    
#: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=OpenXmlBinder&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=OpenXmlBinder&version=1.0.2
                    
Install as a Cake Tool

OpenXmlBinder

OpenXmlBinder is a simple binder for Word OpenXml file. It allows easy filling of word template from C# object in the style of ClosedXml.Reports.

OpenXmlBinder targets .net6 and uses Open-XML-SDK and Open-XML-PowerTools

Installing OpenXmlBinder from nuget

OpenXmlBinder is available through Nuget. It can be installed from the nuget packge manager or from the nuget console.

PM> Install-Package OpenXmlBinder

Usage

OpenXmlBinder is pretty straightforward to use.

  1. Instantiate a OpenXmlBinder with the path to the word template
  2. Use the method binderInstance.AddVariable() to bind any variables
  3. Call binderInstance.Generate() to get a byte array from the template

AddVariable method

Calling AddVariable(string name, string value) allows creation of named variables.

You can also directly call AddVariable(object obj). Each public property (including nested) of the obj will be parsed.

Complete example

Word document template

Word template sample

Code

OpenXmlBinder binder = new OpenXmlBinder("Template/WeatherForecastTemplate.docx");

WeatherForecast forecast = new WeatherForecast
{
    Date = DateTime.Now,
    TemperatureC = Random.Shared.Next(-20, 55),
    Summary = Summaries[Random.Shared.Next(Summaries.Length)],
    Location=new Location("Paris","France")
}

// Binding full object
binder.AddVariable(forecast);

// Adding named variable
binder.AddVariable("Date_Short",DateTime.Now.ToString("d"));

byte[] package = binder.Generate();

// Do whatever you need with the result
return File(package, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "WeatherForecast.docx");
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 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. 
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 428 7/5/2022
1.0.1 289 7/5/2022
1.0.0 280 7/5/2022