我想使用 Java 创建一个 word 文档,并想在文档中添加一个项目符号列表。子弹必须是圆形或复选标记而不是数字。我能够使用 XWPF 创建数字的项目符号列表,但不能创建圆形或复选标记项目符号。请分享一些示例,展示如何使用 Java 在 word 中创建圆形/复选标记类型的项目符号。
问问题
1705 次
1 回答
1
这很难解释,但这里有一个函数:
public static BigInteger addListStyle(XWPFDocument doc, char symbol) throws XmlException{
String styleMaybe = "<w:numbering xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" mc:Ignorable=\"w14 w15 wp14\">\n" +
"<w:abstractNum w:abstractNumId=\""+listStyleIDCounter+"\">\n" +
"<w:nsid w:val=\"6871722E\"/>\n" +
"<w:multiLevelType w:val=\"hybridMultilevel\"/>\n" +
"<w:tmpl w:val=\"8FE6E4C8\"/>\n" +
"<w:lvl w:ilvl=\"0\" w:tplc=\"0410000D\">\n" +
"<w:start w:val=\"1\"/>\n" +
"<w:numFmt w:val=\"bullet\"/>\n" +
"<w:lvlText w:val=\""+symbol+"\"/>\n" +
"<w:lvlJc w:val=\"left\"/>\n" +
"<w:pPr>\n" +
"<w:ind w:left=\"720\" w:hanging=\"360\"/>\n" +
"</w:pPr>\n" +
"<w:rPr>\n" +
"<w:rFonts w:ascii=\"Webdings\" w:hAnsi=\"Webdings\" w:hint=\"default\"/>\n" +
"</w:rPr>\n" +
"</w:lvl>\n" +
"</w:abstractNum>\n" +
"<w:num w:numId=\"1\">\n" +
"<w:abstractNumId w:val=\"0\"/>\n" +
"</w:num>\n" +
"</w:numbering>";
XWPFNumbering numbering = doc.createNumbering();
// genero il numbering style dall'XML
CTAbstractNum abstractNum = CTAbstractNum.Factory.parse(styleMaybe);
XWPFAbstractNum abs = new XWPFAbstractNum(abstractNum, numbering);
// gli imposto un ID univoco
BigInteger id = BigInteger.valueOf(listStyleIDCounter++);
// assegno l'id all'abs
abs.getAbstractNum().setAbstractNumId(id);
// ora aggiungo l'abs al CT del numbering, che mi dovrebbe ritornare lo stesso id
id = numbering.addAbstractNum(abs);
// ora lo aggiungo al numbering creato prima che mi restituirà ancora lo stesso id
return doc.getNumbering().addNum(id);
}
其中listStyleIDCounter
是一个从 0 开始的静态计数器。
您可以通过a
检查符号,=
小圆圈和<
小正方形以及其他更多您可以自己尝试的符号:D
于 2016-03-25T16:55:51.927 回答