I’m trying to search a .odt document file for a placeholder test to replace it and save the file as PDF. It seems to work for regular text, but when the placeholder is inside a table, I get the exception
<code>java.lang.RuntimeException: java.lang.ClassCastException: class org.odftoolkit.odfdom.doc.OdfTextDocument cannot be cast to class org.odftoolkit.simple.Document (org.odftoolkit.odfdom.doc.OdfTextDocument and org.odftoolkit.simple.Document are in unnamed module of loader 'app')
</code>
<code>java.lang.RuntimeException: java.lang.ClassCastException: class org.odftoolkit.odfdom.doc.OdfTextDocument cannot be cast to class org.odftoolkit.simple.Document (org.odftoolkit.odfdom.doc.OdfTextDocument and org.odftoolkit.simple.Document are in unnamed module of loader 'app')
</code>
java.lang.RuntimeException: java.lang.ClassCastException: class org.odftoolkit.odfdom.doc.OdfTextDocument cannot be cast to class org.odftoolkit.simple.Document (org.odftoolkit.odfdom.doc.OdfTextDocument and org.odftoolkit.simple.Document are in unnamed module of loader 'app')
this is the code:
<code> OdfDocument odt = OdfDocument.loadDocument(templateFile);
var root = odt.getContentRoot();
TextNavigation search = new TextNavigation("\{firstLineItemTitle\}", root);
while (search.hasNext()) { //<-- Exception here
TextSelection selection = (TextSelection) search.nextSelection();
var container = selection.getContainerElement();
var parent = container.getParentNode();
//selection.replaceWith(replacement);
}
</code>
<code> OdfDocument odt = OdfDocument.loadDocument(templateFile);
var root = odt.getContentRoot();
TextNavigation search = new TextNavigation("\{firstLineItemTitle\}", root);
while (search.hasNext()) { //<-- Exception here
TextSelection selection = (TextSelection) search.nextSelection();
var container = selection.getContainerElement();
var parent = container.getParentNode();
//selection.replaceWith(replacement);
}
</code>
OdfDocument odt = OdfDocument.loadDocument(templateFile);
var root = odt.getContentRoot();
TextNavigation search = new TextNavigation("\{firstLineItemTitle\}", root);
while (search.hasNext()) { //<-- Exception here
TextSelection selection = (TextSelection) search.nextSelection();
var container = selection.getContainerElement();
var parent = container.getParentNode();
//selection.replaceWith(replacement);
}
Why does this happen? How can I replace contents of a table and preferably get a reference to the table itself to add more rows.