Apodemus.NPOI.XWPFMapper 2.2.2

Suggested Alternatives

Apodemus.NPOI.WordTemplateMapper

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

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

NPOI.XWPFMapper

License Build NuGet Badge

This is a library for mapping objects to Word document tables with the NPOI library.

Usage

You can take a look at the NPOI.XWPFMapper.Example project for a working example.

NPOI.XWPFMapper uses the interface IXWPFMappable and the attribute XWPFPropertyAttribute to define which classes should be mappable and which members should be nested or just strings.

internal class ExampleClass : IXWPFMappable // Implement the IXWPFMappable interface to make a class mappable
{
    public XWPFTableAlignment XWPFTableAlignment { get; set; }

    // Add the XWPFPropertyattribute to make a member mappable.
    [XWPFProperty("Color")] 
    public ExampleEnum Enum { get; set; }

    [XWPFProperty("Name")]
    public string Name { get; set; }

    // This child class also implements IXWPFMappable and will become a nested table.
    [XWPFProperty("Address", XWPFTableAlignment.Column)]
    public ExampleChildClass Address { get; set; }

    // Without the XWPFPropertyAttribute a member will be ignored by the mapping.
    public string IgnoredMember { get; set; }
}

internal class ExampleChildClass : IXWPFMappable
{
    public XWPFTableAlignment XWPFTableAlignment { get; set; }

    [XWPFProperty("Street")]
    public string Address { get; set; }
    [XWPFProperty("Place")]
    public string City { get; set; }
    [XWPFProperty("Country")]
    public string CountryCode { get; set; }
}

In addition to this, there is also the XWPFTableWrapper, which is a class that manages an XWPFTable. It only accepts a single Type to be mapped (excluding its members of course).

XWPFDocument document = new XWPFDocument();

ExampleClass exampleData = new ExampleClass()
{
    Enum = ExampleEnum.Red,
    Name = "This is a test",
    IgnoredMember = "This member will be ignored",
    Address = new ExampleChildClass()
    {
        Address = "Burgemeester Schönfeldplein",
        City = "Winschoten",
        CountryCode = "NL"
    }
};

// XWPFTableWrapper requires a Type argument and an XWPFDocument object to work
// In addition you can optionally set the direction of the table with an enum XWPFTableAlignment (default is Row)

XWPFTableWrapper<ExampleClass> wrapper = new XWPFTableWrapper<ExampleClass>(document, XWPFTableAlignment.Column);
wrapper.Insert(exampleData);

XWPFTableWrapper's XWPFTable is public, so you can access it from XWPFTableWrapper.

Table alignment

Table alignment for nested tables can be set at different points, they are prioritised in the followng order:

  • at the XWPFPropertyAttribute
  • at XWPFTableAlignment of the nested object that implements IXWPFMappable
  • inherited from a parent's XWPFTableAlignment

XWPFTableAlignment.Row

Color Name Address
Red This is a test Van Nelleweg 1, Rotterdam

XWPFTableAlignment.Column

Color Red
Name This is a test
Address Van Nelleweg 1, Rotterdam

🏳️‍⚧️ Trans Rights are human rights!

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  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

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
2.2.2 568 9/19/2022
2.2.0 449 9/17/2022
2.1.0 437 9/17/2022
2.0.0 425 9/16/2022
1.0.0 450 9/16/2022

- Fixed a bug with table alignment assignment