Just thought it might be worth posting the code I have started to play around
with. Nothing special but I think it might be modifiable to work, and it
could serve as a reasonable starting point. The basic approach is as
described in my first post, open a document, get the numbering system
object, get the paragraphs and iterate through them. For each para, try to
get the numID. If that returns null then the paragraph is not in a list, if
a BigInteger object is returned then the para is in a list. If the para is
in a list, check to see that we are not already processing that list - if we
are then this is where concerns around levels and incrementing numbers can
be handled. Also, if the para is in a list and it is a 'new' list, get the
numbering system information. Lots of details to work out but it gets us
onto the first rung of the ladder I think.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package poistuff;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import org.apache.poi.xwpf.usermodel.*;
/**
*
* @author Mark Beardsley
*/
public class NumberingTest {
private final String filename = "C:/temp/Test.docx";
NumberingTest() throws IOException {
File file = null;
FileInputStream fis = null;
XWPFDocument document = null;
XWPFNumbering numbering = null;
XWPFParagraph para = null;
XWPFNum num = null;
List<XWPFParagraph> paraList = null;
Iterator<XWPFParagraph> paraIter = null;
BigInteger numID = null;
int numberingID = -1;
try {
file = new File(filename);
fis = new FileInputStream(file);
document = new XWPFDocument(fis);
fis.close();
fis = null;
numbering = document.getNumbering();
paraList = document.getParagraphs();
paraIter = paraList.iterator();
while(paraIter.hasNext()) {
para = paraIter.next();
numID = para.getNumID();
if(numID != null) {
if(numID.intValue() != numberingID) {
num = numbering.getNum(numID);
numberingID = numID.intValue();
System.out.println("Getting details of the new
numbering system " + numberingID);
System.out.println("It's abstract numID is " +
num.getCTNum().getAbstractNumId().getVal().intValue());
}
else {
System.out.println("Iterating through the
numbers.");
}
}
else {
System.out.print("Null numID ");
}
System.out.println("Text " + para.getParagraphText());
}
}
finally {
if(fis != null) {
fis.close();
fis = null;
}
}
}
}
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/XWPF-Parsing-or-creating-bullet-points-numbered-lists-with-POI-3-8-tp5710800p5710829.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]