Page 1 of 1

Deleting Paragraphs under Last Table

PostPosted: Tue Oct 02, 2018 12:29 am
by tahir
Hi
I want to ask that is there any way for deleting all paragraphs under the last table. Why I am talking about last table? Because I know the index of last table but I have no idea about the strings of paragraphs. So I want to delete everything under last table (say for example 2 or 3). Thanks

Re: Deleting Paragraphs under Last Table

PostPosted: Tue Oct 02, 2018 10:42 am
by jason
How about something like:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
                List<Object> objects = wordMLPackage.getMainDocumentPart().getContent();
                for (int i = objects.size()-1; i>=0; i--) {
                        Object o = XmlUtils.unwrap(objects.get(i));
                        if (o instanceof Tbl) break;
                        // otherwise, remove it
                        objects.remove(i);
                }
 
Parsed in 0.014 seconds, using GeSHi 1.0.8.4


(Untested)