Hello,
About the library:
The error occurs with “Aspose-Word for Java”, version 17.4 as well as 19.4.
Additional info: in rare cases, we still use the old version 13.9.0.0 in other projects. The error I’m about to describe does not happen in these projects and therefore seems to be related to the new versions.
Error Description:
When searching and replacing text placeholders that are present in the document more than once, the placeholders in text boxes are found and replaced in the wrong order: These are not replaced in the order of their appearance in the document, but instead get replaced in a separate process in the end (which is incorrect).
This issue seems to be related (maybe even identical) to another problem I’ve reported in the past about tables. This was solved successfully by you in the past.
I need all placeholders to be found in the exact order of the document (from top to bottom). It used to work that way in earlier Aspose-versions (i.e. 13.9.0.0) without any problems.
Effect on our customers:
As soon as a customer changes within a report, data from customers is shown mixed. This leads to unreliable data generation for our customers.
Steps to reproduction:
I have prepared a simple example with the erroneous scenario: please see the archive file " FindAndReplaceBug2.zip ".
FindAndReplaceBug2.zip (189.8 KB)
Comments and further information can be found in the source code.
At initial startup, inputDocWithTextFields.docx is read and the 10 placeholders found within it are being replaced. 2 of those placeholders refer to loading of the data, while the other 8 show the actual numbers. The result is saved to output.docx.
Currently I’m using the method “com.aspose.words.Range.replace(String pattern, String replacement, FindReplaceOptions options)”.
Further information:
I have also included an altered input file called “inputDocWithoutTextFields.docx” within the archive file which shows that the replacement process works correctly if there are no text boxes present.
Additionally, I have included two .pngs that show the respective failure (new library) or success (old library) with the same input document. This proves that the functionality was working correctly in older versions.
I would be grateful for a swift solution to my problem. Thank you in advance!
Best regards,
Alexander Lyalin
Eudemonia-Solutions.AG