Good day
We are planning on using Aspose.Words to automatically generate monthly reports for our customers. We plan on doing so by creating sub-reports in separate modules. At the moment we have a ‘ticketing’ module collecting data from ServiceNow and a ‘monitoring’ module gathering information from a Check_MK monitoring system. Currently we are in active development and are running into some minor issues.
For generating the reports we make use of the LINQ reporting engine provided by Aspose.Words. The failing report is made up of one master template file and the ticketing module’s dedicated template. The master file contains a title page, a ToC and some version information. The ticketing template consists of 6 headings as well as 6 charts. (Both files are attached to this post in a ZIP archive)
The generation itself is working flawlessly. The problem only occurs when invoking the document.updateFields() method, resulting in an ArrayIndexOutOfBoundsException.
The troubleshooting steps we already took are the following:
- Using a master template only containing a ToC
- Completely rewrote the module’s template file
- Removed any umlauts from the document
- Experimented with different numbers of headings and length of the module’s template
- Deleting chart after chart (which ended in Words no longer throwing the error when using less or equal to 4 charts)
- Reordering the charts in the conflicting module’s template
Our conclusion is as follows:
Whenever there are more than 4 chart objects (no matter in what order or which charts they are) the updateFields method will fail with an “ArrayIndexOutOfBoundsException: 4”. Removing any two charts from the document will let the method pass and update the ToC correctly.
Now to the technical part:
We are using Aspose.Words for Java version 17.3 using not Java as main programming language but Python (with jpype). Now, we know this is not officially supported and we may try implementing a similar process in Java itself, however, if it wasn’t necessary, we would rather not.
The following list describes the steps our application takes while creating a single report (rewritten to Java)
- Load and set the license: License lic = new License(); lic.setLicense(“path”);
- Gather meta data (creation date, customer name etc.)
- Load master template into instance variable: Document doc = new Document(“path”);
- Prepare the reporting engine: ReportingEngine re = new ReportingEngine();
- Generate a sub-report for each module [ collect data, fill Java ArrayList object with information, build the report, return an Aspose.Words Document instance ]
- Append each sub-report to the template file: doc.appendDocument(subdoc, ImportFormatMode.USE_DESTINATION_STYLES); // in a for loop
- Fill in meta data using: re.buildReport(doc, reportMetaData, “reportData”);
- Update document fields: doc.updateFields(); // exception here [catched]
- Save document: doc.save(“path”);
Catching the exception and continuing execution results in a vaild word document. Only the ToC is erroneous showing only ‘?’ instead of page numbers.
I attached the master and the module’s template file (in a ZIP), a full stacktrace and a screenshot of the erroneous ToC as well as our Java classes used to fill in the report data (if of avail; also in a ZIP). If you need anything else, I’m willing to provide further information.
Do you know of any problems regarding the document.updateFields() method? Did we do any (obvious) mistakes?
Thank you in advance.
Kind regards