You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Andreas Seeg <an...@gmail.com> on 2012/12/06 17:25:49 UTC

Re: XWPF - Parsing or creating bullet points/numbered lists with POI 3.8

This is not a question, but I felt the need to type a few lines for
other people who might want to work with bullet points or numberings
in .docx files using the capabilities of Apache POI 3.8.

My original task can be described as extracting certain information
from a specifically formatted word file, and outputting that
information in a simple xml document format. Bullet points and
numberings aren't only specially formatted text, but also implicitly
hold the information about their 'level' compared to other bullet
points or numberings, and I was interested in extracting this
information and to discerning both from each other.

With the great pointers and solutions provided by Mark Beardsley
(again a big thanks for that!) I was able to find out if a paragraph
is part of a numbering/bullet point by checking if
currentParagraph.getDocument().getNumbering().getNum(currentParagraph.getNumID())
returns something different than null. Now, as bullet points are a
special kind of numbering (or the other way around), I still had to
find a way to discern them from each other. Sadly, Apache POI didn't
seem to provide something for that yet, so I extracted this
information manually from the right fragment of the original docx-xml.
Please note that I'm pretty new to java, Apache POI, etc, so this is
probably very ugly for better programmers ;-) :

//First we need the ID of the numbering
BigInteger currentParagraphNumberingID=
currentParagraph.getCTP().getPPr().getNumPr().getNumId().getVal();
//, then use it to find the abstract ID
BigInteger currentParagraphAbstractNumID =
currentParagraph.getDocument().getNumbering().getAbstractNumID(currentParagraphNumberingID);
// and use that one to find the right xml fragment object and turn it
into a string
XWPFAbstractNum currentParagraphAbstractNum =
currentParagraphNumbering.getAbstractNum(currentParagraphAbstractNumID);
CTAbstractNum currentParagraphAbstractNumFormatting =
currentParagraphAbstractNum.getCTAbstractNum();
String numberingFormatXmlAsString =
currentParagraphAbstractNumFormatting.toString();

>From that I built an xml document with the namespace
"http://schemas.openxmlformats.org/wordprocessingml/2006/main", get
its first lvl-element, then the first numFmt-element of the
lvl-element, and from that we extract the value of the "val"
attribute. If that value is "decimal", "lowerLetter", etc, we are
dealing with a numbering, and if not, it is probably a bullet point.
Obviously this method will falsely report a bullet point if we forget
to check for certain values that might indicate a numbering (or
something different than a bullet point), but in my case this sufficed
because we only allow standard numberings in our specially formatted
word file.

In hope that this might help somebody

Andreas Seeg

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: XWPF - Parsing or creating bullet points/numbered lists with POI 3.8

Posted by samik <sa...@yahoo.com>.
Hi,

I am looking for a way to *create *a bulleted/numbered list in a XWPF
document. Do you think it is possible in the current version 3.10?

Thanks,
Samik



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/XWPF-Parsing-or-creating-bullet-points-numbered-lists-with-POI-3-8-tp5710800p5715574.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: XWPF - Parsing or creating bullet points/numbered lists with POI 3.8

Posted by tuncatunc <at...@gmail.com>.
Hi, 
I believe you have a similar problem like mine.
Getting Number from numbered list.
Is there a simple way to do that using groovy/java?

        doc.getParagraphs().each{XWPFParagraph para->
            def numId = para.getNumID()
            if (numId != null){
                def num = numbering.getNum(numId);
                println num.toString() +  para.getText() //+
para.getNumFmt()
            }
        }




--
View this message in context: http://apache-poi.1045710.n5.nabble.com/XWPF-Parsing-or-creating-bullet-points-numbered-lists-with-POI-3-8-tp5710800p5713794.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org