DEV Community

Broggi Quentin
Broggi Quentin

Posted on • Updated on

How to mail merge in .Net with BroggiSoft.OfficeExport

I created a Nuget package, BroggiSoft.OfficeExport, to easily export data to an office document (Word, Excel and PowerPoint).

First you create a template with tags like in Angular, for example you can set a tag {{City}} in your document. In your .Net application, you create for example a Dictionary with City as key and Paris as value and it will be replaced by the corresponding value. This style will be preserved, if you set a tag in italics the new value will also be in italics.

You can also send your data as a json or as an object.

Then you call the OfficeExport’s functions.

For information tags that do not have corresponding values will be removed.

The package also allows you to handle arrays. To do this, create a basic table in Word or PowerPoint and you add a tag like this {{Lines[i].NetIncome}} on a line, this has for effect to replace this line by the first value of your array and add a line for the other rows of your array.

The product key unlocks some features such as arrays support, but you can replace the basic tags without it.

In this example OfficeExport will create a new document OutPut.docx, but you can get the result as a blob.

A Word Template

Become

The output Word Document

Please feel free to provide feedback to me at contact@broggisoft.com.

You will find all the documentation on broggisoft.com.

You can find a test project on GitHub: OfficeExportTest

Top comments (0)