I am using linq.
In my template “docx_in.docx” there is tag: <<[Dummy]>>
java code:
InputStream inputStream = new FileInputStream(new File("/home/aspose/img/docx_in.docx"));
Document document = new Document(inputStream);
ReportingEngine engine = new ReportingEngine();
engine.buildReport(document, values, keys);
document.save("/home/aspose/img/docx_out.docx");
if I do not give parameter “Dummy” into keys I take error :
java.lang.IllegalStateException: An error has been encountered at the end of expression 'Dummy]>'. Can not get the value of member 'Dummy' on type 'class com.aspose.words.net.System.Data.DataRowCollection'.
Is there way to take in document empty string instead <<[Dummy]>>?
Or to take list of all tags to process them manually?
Like document.getMailMerge().getFieldNames()?
Thanks!
While using the latest version of Aspose.Words i.e. 18.7, we managed to reproduce this issue on our end. We have logged this issue in our bug tracking system. The ID of this issue is WORDSNET-17129. Your thread has also been linked to this issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.
and value of placeholder ‘ProductTable’ is not filled, we get an error like:
java.lang.IllegalStateException: An error has been encountered at the end of expression 'item in ProductTable]>'. Can not get the value of member 'ProductTable' on type 'class ...'.
Is it possible to have the following: when there is no ‘ProductTable’ value to interpret it like an empty DataSource?
Please ZIP and attach your input Word document and piece of source code to reproduce the same problem on our end. We will then investigate the issue on our end and provide you more information.
With empty placeholders, everything works good.
But now we have problems with empty variables.
If we assign the value of a placeholder to the variable, and then we try to use it, we get errors.
A simple example.
Variable ‘varCollection’, placeholder ‘collection’ is not filled.
Template: << var [varCollection = collection] >> << foreach [element in varCollection] >> element << / foreach >>
Error:
An error has been encountered at the end of the expression 'element in varCollection]>'. Can not iterate over an instance of type 'class java.lang.Object'.
Is it possible not to generate an exception in this situation?
Please ZIP and attach your simplified Word document and piece of source code to reproduce the same problem on our end. We will then investigate the issue on our end and provide you more information.
I created unit test with this problem: https://gitlab.com/pegoopik/aspose-research/merge_requests/4
error:>
java.lang.IllegalStateException: An error has been encountered at the end of expression 'element in varCollection] '. Can not iterate over an instance of type ‘class java.lang.Object’.
at asposewobfuscated.zzP3.zzZu(Unknown Source)
at asposewobfuscated.zzP3.zzZ(Unknown Source)
at asposewobfuscated.zzP3.zzY(Unknown Source)
at asposewobfuscated.zzOP.zzOC(Unknown Source)
at asposewobfuscated.zzVT.zzWb(Unknown Source)
at asposewobfuscated.zzOP.zzZ(Unknown Source)
at asposewobfuscated.zzDA.zzZ(Unknown Source)
at com.aspose.words.ReportingEngine.buildReport(Unknown Source)
at ru.pegoopik.aspose.linq.tests.empty_placeholder.EmptyVarTest.testEmptyCollection(EmptyVarTest.java:58)
We have logged your requirement in our issue tracking system. Your ticket number is WORDSNET-17670. We will further look into the details of this problem and will keep you updated on the status of the linked issue.
WORDSNET-17670 is actually not a bug in Aspose.Words. The exception is intended as it indicates wrong template syntax.
The reason for the exception in this case is that ReportBuildOptions.ALLOW_MISSING_MEMBERS makes the engine to treat missing members as null literals (see the option’s description for more information). But a variable is not a null literal, even if its value is set to null through a literal. Since the type for the variable in the template is not set explicitly and it cannot be determined implicitly (from a null literal), its type is considered to be Object. But a foreach tag requires an expression of type implementing Iterable. So the exception is thrown.
However, there is a simple way to make it work. Please check the attached modified template (html (3) modified.html). Please note that it is also required to add a known type for the engine as shown in the following code snippet: