I have used a custom DocumentVisitor, but on one document, it’s weird that DV doesn’t visit the table.
test.zip (46.2 KB)
here’s the test document and the corresponding code. I have debugged
however , it passed the table. Is it because of the HeaderFooter ?
@Madecho As I can see there are 6 tables in your document and all of them are visited properly by the following simple code:
Document doc = new Document("C:\\Temp\\in.docx");
doc.accept(new TestTableVisitor());
private static class TestTableVisitor extends DocumentVisitor
{
@Override
public int visitTableStart(Table table) throws Exception {
System.out.println("Table start");
return VisitorAction.CONTINUE;
}
}
sorry Alexey, would you mind checking my DocumentVisitor Code? I think I had the same code as you. but I don’t know how it ends. I debugged every possible point i could think of
@Madecho You have the following code in your visitor:
if (endOfCover(text)) {
return VisitorAction.STOP;
}
Most likely this is the place where the visitor stops.
1 Like
I looked at the code you mentioned, however,
if( paragraph.getParentNode().getNodeType() != NodeType.BODY){
return VisitorAction.CONTINUE;
}
if (mIgnoreParagraph) {
return VisitorAction.CONTINUE; // 如果是 Table 内的 Paragraph,跳过打印
}
String text = paragraph.getText().trim().replace(" ", "");
if (endOfCover(text)) {
return VisitorAction.STOP;
}
it’s due to the code
if( paragraph.getParentNode().getNodeType() != NodeType.BODY){
return VisitorAction.CONTINUE;
}
that I added that really worked. why ? i just skip the paragraph in the headfooter, and it can read the row in a table. that’s confusing.
@Madecho Please check this condition to the following:
if(paragraph.getAncestor(NodeType.BODY) == NodeType.BODY){
return VisitorAction.CONTINUE;
}