Hi all,
I’m using the Aspose.Words.Reporting library in Version 21.5.
We use a word template which consists of a table with two colums:
Column 1 displays the heading which is only supposed to show if values in an array are existing.
<<if [...]>> <<foreach [...]>>
Column 2 then displays the result of the array.
<<[...]>> <</foreach>> <</if>>
This line of code is followed by more rows displaying different items.
The above structure itself works. If no entrires are part of the array, nothing is displayed. Unfortunately if that happens, the pdf shows a large white empty space and my assumption was that not even this space is shown.
The reason might be the table structure? Any possibility to fix that?
@ThomasWilken
Am I getting it right that you mean extra whitespaces at Column 2 when outputting array items using <<[...]>>
? If so, then it is required to remove extra whitespaces between tags in a template as follows:
<<[...]>><</foreach>><</if>>
If my understanding is not correct, please provide more details such as a complete simplified template, data, and code, so we could further look into the issue.
Template.docx (66.1 KB)
Hi, sry for the confusion. I tried to upload a simple template.
If there are entries as part of the array, the output is correct and looks like this:
Row1: Some code
Row2: Some code:
Row3: Output
Row4: Output
Row5: Some code
If the array is empty, i want it to look like this:
Row1: Some code
Row2: Some code:
Row3: Some code
… but instead it looks like this:
Row1: Some code
Row2: Some code:
Row3: (empty row)
Row4: (empty row)
Row5: Some code
Any chance to get the output i want?
@ThomasWilken
I have modified your template to use test data and check how the template is processed by the engine and was not able to reproduce the reported issue. Please check Template Modified.docx (66.4 KB). The template is transformed to Template Modified Out.docx (58.3 KB) by the engine on our end.
If the issue is still present on your end, I think, its reason could be not the template but data. Could you please share sample data causing the issue as well?
Hi,
thanks for the reply,
If there’s no (1, 2, 3) I assume the rows will still be visible? Because that’s exactly what I want to avoid…
example.docx (66.6 KB)
code.docx (24.0 KB)
Here’s some example codeand the corresponding aspose code. It actually looks a little diferent than before, but that’s basically what we use.
And this produces the empty brakes. If we have no instance of “c” currently the aspose code wouldn’t work at all. Therefore if there’s no value in the array, we currently sho one value like this:
“value5”: “” (see word file)
@ThomasWilken
The modified template in my previous post shows both cases: when rows are shown and hidden upon a condition. In the latter case, no empty rows show up as you requested.
Thanks for sharing the details. Indeed, this template (example.docx) significantly differs from the one you shared previously (Template.docx). In this case, an empty row appears, because if
tags affect contents within individual cells rather than whole rows. To affect whole rows instead, you can move closing if
tags to the last table column. Please check example Modified.docx (66.4 KB).
By default, LINQ Reporting Engine does not allow to use object members missing in a data source. However, by applying ReportBuildOptions.AllowMissingMembers
, you can make the engine to treat missing object members as null literals. See Accessing Missing Members of Data Objects for more information.
Hi there,
I tried your example and moved the closing if-statement to the second column. Nothing else was changed.
The result though shows the row and “Headline” without any entry in column two.
Does it have to do with the “value5”: “”? Maybe the engine still interprets it as an actual result?
@ThomasWilken
Unfortunately, your requrement is not clear enough. Could you please ZIP and attach here the following resources for testing:
- An actual template (without sensitive data)
- Actual data (without sensitive information)
- Actual code in a programming language you use to build a report
- An expected result document created manually in MS Word
As soon as we get these pieces of information, we will be in a better position to assist you further. Thanks for your cooperation.
Aspose.zip (210.0 KB)
Hi there,
please find attached a zip file. Sorry for all the confusion.
@ThomasWilken
We have modified your template to match expected outputs. Please check Test Template Modified.docx (40.3 KB).
Awesome, thanks a lot. That worked
1 Like
Hi all,
I got another question in regards to the same template:
For the part of Sum Insured: <<[product.limitationSumInsured]>>
we wanted to input the currency separators like this:
<<[product.limitationSumInsured(f => Integer.parseInt(f.varNumber))]:”#,##0”>>
Unfortunately we ended up with the following error message:
"exceptionMessage": "Error creating document. Please verify json or template file. An error has been encountered at the end of expression 'benefit.SumInsured(f => '. Can not iterate over an instance of type 'System.Data.DataRow'."
Anything we can do here?
@ThomasWilken
Could you please ZIP and attach here the following resources for reproducing of the issue:
- An actual template (without sensitive data)
- Actual data (without sensitive information)
- Actual code in a programming language you use to build a report
Hi there, it’s the same template and same data as before. I just changed the limitationSumInsured part
@ThomasWilken
Judging by “System.Data.DataRow
” in the exception message, you use .NET. But judging by Integer.parseInt
in your template, it seems like you are trying to use Java syntax. Could you please clarify what platform (.NET or Java) do you use?
Also, it seems like you want to parse integer values by yourself. Do not built-in facilities of JsonDataSource
work for you?
Hi there,
yes, we use .NET. I found the integer.parseInt codesnippet in thisforum, but I guess I can’t use it then.
Also I’m not familiar with JsonDataSource
I’m afraid, how could it be used?
@ThomasWilken
JsonDataSource
helps to work with JSON using LINQ Reporting Engine. For more information, see Accessing JSON Data.
As a note, you have shared your template and data, but not your code in a programming language. Could you please share it as well? This would greatly help us to understand your scenario.
P.S.: There is no need to share whole code of your system, a snippet dealing with ReportingEngine
is enough.
Hi there,
I actually don’t know the programming code. All we do is call the API with the JSON and the template. I will try to get the snippet you asked for.
Regarding the JSON itself, i can’t change directlyfrom string to integer. It alwasneeds to be
variable: "value
"
as otherwise the test in the template if a row is shown or not wouldn’t work.
Do you see an option to do the conversion in the template itself?
@ThomasWilken
Please also share your actual programming code. Without knowing which options are used to load JSON, we can only make assumptions on how to change the template. Thanks for your cooperation.