Apodemus.NPOI.XWPFMapper
2.2.2
dotnet add package Apodemus.NPOI.XWPFMapper --version 2.2.2
NuGet\Install-Package Apodemus.NPOI.XWPFMapper -Version 2.2.2
<PackageReference Include="Apodemus.NPOI.XWPFMapper" Version="2.2.2" />
paket add Apodemus.NPOI.XWPFMapper --version 2.2.2
#r "nuget: Apodemus.NPOI.XWPFMapper, 2.2.2"
// 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
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 implementsIXWPFMappable
- 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 | Versions 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. |
-
.NETCoreApp 3.1
- Microsoft.CSharp (>= 4.7.0)
- NPOI (>= 2.5.6)
-
.NETFramework 4.8
- Microsoft.CSharp (>= 4.7.0)
- NPOI (>= 2.5.6)
-
.NETStandard 2.0
- Microsoft.CSharp (>= 4.7.0)
- NPOI (>= 2.5.6)
-
.NETStandard 2.1
- Microsoft.CSharp (>= 4.7.0)
- NPOI (>= 2.5.6)
-
net5.0
- Microsoft.CSharp (>= 4.7.0)
- NPOI (>= 2.5.6)
-
net6.0
- Microsoft.CSharp (>= 4.7.0)
- NPOI (>= 2.5.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- Fixed a bug with table alignment assignment