Reputation: 85
I'm trying to make an application which would read a word file (docx) and do some stuff with it. So far, I've done pretty much everything except for to identify bullets. I can find isBold(), isItalic(), isStrike() but I cannot seem to find isBullet()
can anyone please tell me how to identify bullets?
the application is built in Java
Upvotes: 1
Views: 3474
Reputation: 31
You can use below code for getting list of all the bullets from the word document. I have used apache poi's XWPF api.
public class ListTest {
public static void main(String[] args) {
String filename = "file_path";
List<String> paraList = new ArrayList<String>();
try {
// is = new FileInputStream(fileName);
XWPFDocument doc =
new XWPFDocument(OPCPackage.open(filename));
List<XWPFParagraph> paragraphList = doc.getParagraphs();
for(XWPFParagraph para :paragraphList) {
if((para.getStyle()!=null) && (para.getNumFmt() !=null)) {
paraList.add(para.getText());
}
for(String bullet :paraList) {
System.out.println(bullet);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Upvotes: 0
Reputation: 48386
There's no isBullet()
method, because list styling in Word is quite a lot more complicated than that. You have different indent levels, different styles of bullets, numbered lists and bulleted lists etc
Probably the easiest method for you to call for your use case is XWPFParagraph.html.getNumFmt():
Returns numbering format for this paragraph, eg bullet or lowerLetter. Returns null if this paragraph does not have numeric style.
Call that, and if you get null it isn't a list, and if it is, you'll know if it's bulleted, number, letter etc
Upvotes: 4