Page 1 of 1
finding the text corresponding the numbers docx
Posted:
Fri May 18, 2012 4:55 pm
by shashankdass
Hi
I am quite new to docx4j
I have a docx file in which there is a numbered list. I just want to extract text corresponding to that number and make a hashmap of number and value.
I tried almost everything given on net which includes imitation of AbstractNumberinTest way given with Docx4j. But nothing seems to work.
Please help, Need it badly.
Thanks
Re: finding the text corresponding the numbers docx
Posted:
Fri May 18, 2012 6:41 pm
by jason
Iterate through the paragraphs comprising the list and for each p, get its pPr. Then, something like:
Using java Syntax Highlighting
if ( pPr
!=null ) {
String pStyleVal
=null;
// Set @class
if (pPr.
getPStyle()!=null
&& pPr.
getPStyle().
getVal()!=null) {
pStyleVal
= pPr.
getPStyle().
getVal();
}
// Numbering
String numberText
=null;
String numId
=null;
String levelId
=null;
if (pPr.
getNumPr()!=null) {
numId
= pPr.
getNumPr().
getNumId()==null ? null : pPr.
getNumPr().
getNumId().
getVal().
toString();
levelId
= pPr.
getNumPr().
getIlvl()==null ? null : pPr.
getNumPr().
getIlvl().
getVal().
toString();
}
ResultTriple triple
= org.
docx4j.
model.
listnumbering.
Emulator.
getNumber(
wordMLPackage, pStyleVal, numId, levelId
);
if (triple
==null) {
log.
debug("computed number ResultTriple was null");
} else {
if (triple.
getBullet() != null) {
numberText
= (triple.
getBullet() + " ");
} else if (triple.
getNumString() == null) {
log.
error("computed NumString was null!");
numberText
= ("?");
} else {
numberText
= (triple.
getNumString() + " ");
}
}
if (numberText
!=null) {
// Do whatever
}
}
Parsed in 0.017 seconds, using
GeSHi 1.0.8.4
Re: finding the text corresponding the numbers docx
Posted:
Sat May 19, 2012 1:54 am
by shashankdass
Thanks Jason for a quick reply.
I was not using getBullet method for geting string. But i tried using it now and it is returning null to me. When i used getNumString() it is returning me the numbers succesfully though.
Thanks in advance for wonderful support.
Re: finding the text corresponding the numbers docx
Posted:
Sat May 19, 2012 5:53 pm
by shashankdass
Please help.. I tried the same method suggested by you..but getBullet method is returnign null..