我用代码写的时候,发现实现不了这种需求,但是用 word 是可以实现这种功能的,当我结束列表后,插入文本,在此开启列表,列表就不连续了,请问这种能够实现吗
列表.docx (14.6 KB)
@myboy 您可以使用以下代码来实现结果:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getListFormat().applyBulletDefault();
builder.writeln("AAA");
builder.writeln("BBB");
builder.getListFormat().listIndent();
builder.writeln("B1");
builder.writeln("B2");
builder.writeln("\t\t\t\t\t\thello");
builder.write("B3");
ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
for (Paragraph paragraph : paragraphs) {
if (paragraph.getText().contains("hello")) {
paragraph.getListFormat().removeNumbers();
}
}
doc.save("output.docx");
谢谢,成功实现了我的需求