We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Document Visitor API - visitTableStart not picking table

Using the DocumentVisitor API - table is not coming in table start method. Document attached. Please help on this.

public int visitParagraphStart(final Paragraph paragraph) {
        String style = paragraph.getParagraphFormat().getStyle().getName();
        
            System.out.println("[ In paragraph ] ");
            System.out.println("    [ paragraph text ] "+paragraph.getText());
        
        return VisitorAction.CONTINUE;
    }

    public int visitTableStart(final Table table) {
       
        String style = table.getStyle().getName();
       
            System.out.println("[ In table ] ");
            System.out.println("    [ table text ] "+table.getText());
           
        return VisitorAction.CONTINUE;
    }

    public int visitTableEnd(final Table table) {
     
        String style = table.getStyle().getName();
        System.out.println("In table end - style "+style);
 
        return VisitorAction.CONTINUE;
    }

table_not_parsing_issue.docx (16.2 KB)

HI @hkcw3

Can you send me how are you invoking the methods that you described? I need to see how are you handling the doc.

@mlyra
Attaching full code here -

Document Visitor Implementation

public class DocumentVisitorV3 extends DocumentVisitor {

    public int visitParagraphStart(final Paragraph paragraph) {
        String style = paragraph.getParagraphFormat().getStyle().getName();
        System.out.println("[ In paragraph ] ");
        System.out.println("    [ paragraph text ] " + paragraph.getText());
        return VisitorAction.CONTINUE;
    }

    public int visitTableStart(final Table table) {
        String style = table.getStyle().getName();
        System.out.println("[ In table ] ");
        System.out.println("    [ table text ] " + table.getText());
        return VisitorAction.CONTINUE;
    }

    public int visitTableEnd(final Table table) {
        String style = table.getStyle().getName();
        System.out.println("In table end - style " + style);
        return VisitorAction.CONTINUE;
    }

}

Calling Document Visitor -

public static void main(String[] args) throws Exception {
        AsposeLicenseLoader.loadAsposeWordLicense();
        DocumentVisitorV3 documentVisitorV3 = new DocumentVisitorV3();
        Document document = new Document("/Users/hemant/table_not_parsing_issue.docx");
        document.accept(documentVisitorV3);
    }

Hi @hkcw3,

I could not reproduce the problem in my environment. I am using Aspose words 22.2 with jdk 17. I will share my output with you. Can you please share the version of Aspose.Words that you are using? It would be nice if you also share the output of your program.output.zip (587 Bytes)