Hi,
I am using the below method to remove a table from the word document using docx4j3.2.2. This code works fine in weblogic 11g and java 1.6.
However, I execute the same code in weblogic 12c and java 1.8 and the code does not remove the table. Also, there is no error or exception thrown by the code. The weblogic is installed on UNIX server.
Can you please help.
Tbl hdrTbl = TableUtil.getInstance().getFirstTable(factory, pkg);
if (hdrTbl != null) {
loggerUtil.logTrace("Removing the first table from the document");
pkg.getMainDocumentPart().getContent().remove(hdrTbl.getParent());
}
public Tbl getFirstTable(ObjectFactory factory, WordprocessingMLPackage pkg) {
Tbl headerTable = null;
loggerUtil.logTrace("Start of method getFirstTable");
try {
List<Object> tbllst = getAllElementFromObject(pkg.getMainDocumentPart().getContents(), Tbl.class);
if (tbllst.size() > 0) {
Tbl currentTable = (Tbl) tbllst.get(0);
List<Object> rows = getAllElementFromObject(currentTable,Tr.class);
for (int i = 0; i < rows.size(); i++) {
Tr tr = (Tr) rows.get(i);
List<Object> cells = tr.getContent();
for (Object o2 : cells) {
Tc tc = null;
String value = "";
if (o2 instanceof javax.xml.bind.JAXBElement
&& ((JAXBElement<?>) o2).getDeclaredType().getName().equals("org.docx4j.wml.Tc")) {
tc = (org.docx4j.wml.Tc) ((JAXBElement<?>) o2).getValue();
value = tc.getContent().get(0).toString();
if (value.contains(
Constant.SAMPLE_DATE)) {
loggerUtil.logTrace("Document first table contains 'SAMPLE DATE'");
return currentTable;
}
}
}
}
}
} catch (Exception e) {
loggerUtil.logError("Error in method getFirstTable", e);
e.printStackTrace();
}
loggerUtil.logTrace("End of method getFirstTable");