I have a word template that has multiple similar tables and some paragraphs associated to those tables placed just before them. Depending on the amount of data, I populate some tables and others are not required, so are there paragraphs.
I need to remove these tables and paragraphs. As you can see in the image, I need to remove Table 2 and its paragraph Table Parahgraph
Please help me how to do it. I tried using document.removeBodyElement(pos) , but it does not help.
int startIndex = 0;
int endIndex = 0;
startIndex = doc.getPosOfTable(doc.getTables().get(0));
startIndex++;
endIndex = doc.getPosOfTable(doc.getTables().get(1));
System.out.println("startIndex "+ startIndex);
System.out.println("endIndex "+ endIndex);
for(int i=startIndex; i<=endIndex; i++){
doc.removeBodyElement(i);
}