In org.docx4j.model.table.TableModel.handleRow, I am for every table, hitting the 'log.warn' line below:
- Code: Select all
private void handleRow(NodeList cellContents, Tr tr, int r) {
//...
for (Tc tc : tcFinder.tcList) {
Node wtrNode = cellContents.item(r); // w:tr
if (wtrNode==null ) {
log.warn("Couldn't find item " + r);
}
addCell(tc, getTc(wtrNode, c, new IntRef(0)));
//...
}
}
This then breaks the code in the next line, since getTc() is being passed a value of 'wtrNode==null' and can't then run wtrNode.getChildNodes().getLength()
- Code: Select all
private Node getTc(Node wtrNode, int wanted, IntRef current) {
for (int i=0; i<wtrNode.getChildNodes().getLength(); i++ ) {
//...
wtrNode is calculated by 'cellContents.item(r)' (Note, both 'cellContents' and 'r' are both passed as parameters and are not used anywhere else within the function or sub-functions, so it would be best to not only pull the 'Node wtrNode = ...' line outside the 'for' loop, but also change the parameters to handleRow(Node wtrNode, Tr tr) and have wtrNode calculated by any calling function). handleRow is called by 'build'. 'r' is a counter of the number of table rows found by TraversalUtil on a w:tbl, and cellContents is the NodeList version of these rows.
- Code: Select all
public void build(Tbl tbl, Node content) throws TransformerException {
//...
NodeList cellContents = content.getChildNodes(); // the w:tr
TrFinder trFinder = new TrFinder();
new TraversalUtil(tbl, trFinder);
int r = 0;
for (Tr tr : trFinder.trList) {
startRow();
handleRow(cellContents, tr, r);
r++;
}
}
Essentially, what's happening here is:
- Code: Select all
trFinder.trList.size() == (cellContents.getLength() + 1)
//resulting in...
cellContents.item(r) == null
//where r=trFinder.trList.size);
I wonder whether the problem lies with TraversalUtil, its params, or content...?
In any case i'm giving up on this front for now!