Document generation from template using reporting engine

Hi,

I am currently using a IDataRecord to create a map of the template fields and values in order to build the report. This is working as expected with a simple template where the fields are all directly replaced with some string values. However I would like to modify this template to accept the following.

  1. Is it possible to have a mix of values that are regular strings as well as values that are html and will render in the template?
  2. Is it possible to have a data record where the values can be string or list<map<string, string>>? In the template I would like to loop through the list and use the maps for replacements of fields multiple times.

I am attaching a document to further detail question 2:
asposeWordsQuestion.zip (19.5 KB)

Please provide some examples for 1 or 2 if possible.

Thanks,
Monica

@mmaslowski,

We are working on your query and will get back to you soon.

@mmaslowski,

I am afraid, we do not fully understand this question. If you ask how to output some values to be formatted as HTML whereas the other ones to be formatted as plain text, then it can be done using the html switch in a template as follows:

DocumentBuilder builder = new DocumentBuilder();
builder.Writeln("<<[\"not HTML\"]>>");
builder.Writeln("<<[\"<b>HTML</b>\"] -html>>");

ReportingEngine engine = new ReportingEngine();
engine.BuildReport(builder.Document, new object());

builder.Document.Save("D:\\Temp\\18.6.docx");

If your requirement is about a single particular value that in some circumstances can be an HTML string and sometimes can be a plain text string, then you can apply the html switch in a template to such a value. When the value is an HTML string, then it is formatted accordingly. When it is a plain text string, it is outputted as plain text, no crashes occur. This is illustrated in the following code snippet:

DocumentBuilder builder = new DocumentBuilder();
builder.Writeln("<<[\"not HTML\"] -html>>");

ReportingEngine engine = new ReportingEngine();
engine.BuildReport(builder.Document, new object());

builder.Document.Save("D:\\Temp\\18.6-.docx");

This can be done using an IDataReader implementation. You can find an example on this here.

code.zip (1.7 KB)

But note that this example is quite complex, so you may want to simplify it. We think that implementation of the DataReader class form the example is enough for you.

Also, if you want to deal with single values and list values at the same time, then this can be done by passing multiple data sources to the engine, one of which is IDataRecord and the other one is IDataReader.

Ok got this working now, thank you so much.