OpenXmlBinder 1.0.2
dotnet add package OpenXmlBinder --version 1.0.2
NuGet\Install-Package OpenXmlBinder -Version 1.0.2
<PackageReference Include="OpenXmlBinder" Version="1.0.2" />
paket add OpenXmlBinder --version 1.0.2
#r "nuget: OpenXmlBinder, 1.0.2"
// Install OpenXmlBinder as a Cake Addin
#addin nuget:?package=OpenXmlBinder&version=1.0.2
// Install OpenXmlBinder as a Cake Tool
#tool nuget:?package=OpenXmlBinder&version=1.0.2
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.
- Instantiate a OpenXmlBinder with the path to the word template
- Use the method binderInstance.AddVariable() to bind any variables
- 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
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 | Versions 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. |
-
net6.0
- DocumentFormat.OpenXml (>= 2.17.1)
- OpenXmlPowerTools (>= 4.5.3.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.