Parse word template to identify the business objects required for JSON data source

Thank you very much. It works. However, when I try to populate into a table with foreach loop outside table it gives, error

System.InvalidOperationException
  HResult=0x80131509
  Message=An error has been encountered at the end of expression 'person.Name]>'. Can not get the value of member 'person' on type 'System.Data.DataRow'.

I will
Template1.docx (20.3 KB)

attach my template where does not work.

@NaraSg The table in your template is floating and it’s actual position in the document object model is before opening tag of foreach. Just make the table inline to see the problem. Here is the modified template:
in.docx (20.3 KB)

Thank you. It works with error but my expectation was that the table will be repeated multiple times for each list item. However, we that it overwrites on the same row. How to show multiple tables, one for each item in the list.
FilledDocument.docx (14.1 KB)

Attached the expected document
FilledDocumentExpected.docx (21.2 KB)
But want it to be separate tables, not as one table with headers in between. What is seen in the document is very similar to having foreach in header

@NaraSg The problem occurs because table is floating in your document. Please try avoid using floating tables. You can simply set ReportBuildOptions.RemoveEmptyParagraphs to get the expected output:

JsonDataSource ds = new JsonDataSource(@"C:\Temp\data.json");

Document doc = new Document(@"C:\Temp\in.docx");

ReportingEngine engine = new ReportingEngine();
engine.Options = ReportBuildOptions.RemoveEmptyParagraphs;
engine.BuildReport(doc, ds, "Persons");
            
doc.Save(@"C:\Temp\out.docx");

out.docx (14.1 KB)

Yes, will try out.
Thk you

1 Like

Hello,

Attached is a template & json data source. I am unable to render the Data in the third row (first two rows are headers) onwards
Template1.docx (30.0 KB)

data.zip (745 Bytes)

"TableData": [
      {
        "Data": [
          "1",
          "1",
          "10.551",
          "10.551",
          "30.551"
        ]
      },
      {
        "Data": [
          "1",
          "1",
          "10.551",
          "10.551",
          "30.551"
        ]
      },
      {
        "Data": [
          "1",
          "1",
          "10.551",
          "10.551",
          "30.551"
        ]
      },
      {
        "Data": [
          "1",
          "1",
          "10.551",
          "10.551",
          "30.551"
        ]
      },
      {
        "Data": [
          "1",
          "1",
          "10.551",
          "10.551",
          "30.551"
        ]
      }
    ]

Please help to understand

@NaraSg

By looking at your data (that is, an array of arrays), it seems like the thing you expect in a result document is a cross (pivot) table. Working with Cross (Pivot) Tables explains how to build those.

Some points to note:

  • For a table-row data band occupying one table column, a greedy switch should be applied to a closing foreach tag (see the last part of Working with Table-Row Data Bands).

  • Operator ++ is not supported by LINQ Reporting Engine. The list of supported operators can be found at Using Operators.

  • To reference an item of a simple-type JSON array in a template, the name of the array plus “_Text” suffix should be used as per the second note at Accessing JSON Data.

Combining all these, the last cell of your template table should contain something like this:

<<foreach [in ResultTable.TableData]>><<foreach [in Data] -horz>><<[Data_Text]>><</foreach>><</foreach -greedy>>

Hello ,
Thank you for the pointers on Pivot tables & accessing data arrays
I tried your suggestion. Get the attached error. please help to understand.
System.InvalidOperationException.zip (614 Bytes)

Template1.docx (30.2 KB)

Regards,
NaraSg

@NaraSg

This part is not considered in your template, which causes the exception. However, when adding a greedy switch, another exception is thrown, which is unexpected. We are about to log the issue for the sake of correction. After it is fixed, your template should be modified to include a greedy switch as per the quote.

@NaraSg

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-28338

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like

Thank you for the support. In the meantime, I will continue to evaluate other features that may be help our use cases

1 Like

Hello,
When using word templates, I notice that the replaced text follows the formatting (font, color) of evaluated expression. I like the feature very much. However, I have cases where the expressions are lengthy & I want to keep the font size smaller for those lengthy expression and have different formatting for replaced text. Is it possible?

@NaraSg You can try using HTML to specify formatting of the inserted value that differs from the formatting of the tag. But I would prefer to keep value formatting the same as formatting of the tags. This make easier to analyze the output.

Hello Support Team,
My test data can include multiple sections or types of information. Depending on the report type (concise or detailed), not all of this information may be needed. I understand that we connect to the data source, and during rendering, the relevant data is filled in accordingly. So, the data source should contain all the possible information.

Is there a parsing phase where I can determine which parts of the data to include in the data source based on the report type?

Regards,

@NaraSg Unfortunately, Aspose.Words does not have additional parts for this. You need to parse the data before using the Reporting Engine.

Thank you. Similar to the mustache syntax {{ }}, is there any way for me to add my own custom syntax, that I parse & then remove all those (custom syntax) in the final report (looking for a function similar to ReportBuildOptions.RemoveEmptyParagraphs to remove those custom syntax)?

Regards,
NaraSg

@NaraSg To remove the custom syntax, you need IReplacingCallback Interface | Aspose.Words for .NET to find it, for example with Regex regex = new Regex(@"<<([^>]+)>>");.

Thank you very much.

Regards,

1 Like

The issues you have found earlier (filed as WORDSNET-28338) have been fixed in this Aspose.Words for .NET 25.8 update also available on NuGet.