Please share the sample code structure to implement the below features using LINQ reporting engine in aspose.word for JAVA along with JSON Data
Inserting “N” number of documents dynamically into Main Document while building the engine during runtime.
Number formatting Syntax: - Input amount : 123456.0000 Expected Output Amount : 123,456.00 (millions comma separator with two decimal places).in Tag format
String formatting Syntax:- Splitting / replacing the string while executing the tag
Please ZIP and attach JSON data along with input documents and expected output document. We will then provide you more information about your query along with code example.
Please use the following template syntax to format the number.
Payment: <<[payment]: "##,####.00">>
Unfortunately, Aspose.Words does not support this feature. We have logged it as WORDSNET-20654 in our issue tracking system. You will be notified via this forum thread once this feature is available. We apologize for your inconvenience.
Please use the following template syntax to sort the data by year, and display the name with comma separated values.
Name: <<[name]>>, Age: <<[age]>>, full address: <<[fulladdress] >>
Payment: <<[payment]: "##,####.00">>
<<foreach [in gear.Where(g => g.year == “1983”)]>><<[name]>>,<</foreach>>
<<foreach [in gear.OrderBy(g => g.year)]>>
Name : <<[name]>>
Year : <<[year]>>
<</foreach>>
Following code example shows how to use the JSON data source with above template.
Document doc = new Document(MyDir + "templateJson.docx");
var json = File.ReadAllText(MyDir + "JSON_Data.json");
JsonDataLoadOptions options = new JsonDataLoadOptions();
options.SimpleValueParseMode = JsonSimpleValueParseMode.Strict;
var dataStream = new MemoryStream(Encoding.ASCII.GetBytes(json));
var jsonDataSource = new JsonDataSource(dataStream, options);
var engine = new ReportingEngine();
engine.BuildReport(doc, jsonDataSource);
doc.Save(MyDir + "20.6.docx");
Please use following template and code example to insert documents dynamically.
We have closed the issue WORDSNET-20654. You export the comma separated value in paragraphs using following template and code example.
<<foreach [item in Arrays.asList(person.fulladdress.split(“,”))]>>
<<[item]>>
<</foreach>>
Document document = new Document("template.docx");
ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.REMOVE_EMPTY_PARAGRAPHS); // This is needed to remove extra empty paragraphs.
engine.getKnownTypes().add(java.util.Arrays.class); // This is needed to use static members of the Arrays class in the template.
engine.buildReport(document, new JsonDataSource("JSON_Data.json"), "person");
document.save("out.docx");
Another issue in JSON Data source to merge with template using reporting engine.
In listing of JSON Array Object, if any one of the object is null, reporting engine is skipping to render the details for all json array object which holds the data into the generated template.
Please refer the attached Zip package for sample input and expected outSample_Package.zip (23.3 KB)
put details
Please use ReportingEngine.Options as shown below to get the desired output. Hope this helps you.
Document document = new Document(MyDir + "sampletemplate.docx");
ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS); // This is needed to remove extra empty paragraphs.
engine.buildReport(document, new JsonDataSource(MyDir + "managers.json"), "managers");
document.save(MyDir + "out.docx");
Already i added this “allow-missing-members” into engine builder option while building the report.
But, Still facing the same issue as Engine doesn’t support to render all managers contract details into generated output document if any one of the managers contract details as null.
Please refer the sample managers.json file( which contain one of the contracts array object as null) along with Sampleoutput document as we have shared already.
We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-20711. You will be notified via this forum thread once this issue is resolved.