如何设置目录的字体样式,包括poi word中的字体颜色,字体大小和粗体?
我使用doc.createTOC();
生成poi word(XWPF)中的目录,并使用addCustomHeadingStyle(doc, ChapterLvl.LVL_1.style, 1);
生成标题Content,虚线和页码.但是我想设置不同的标题级别的标题内容具有不同的字体大小,字体颜色,粗体以及虚线和页码具有与相应的标题内容相同的样式,例如图片附件,有人可以给我一些建议怎么做?
I using doc.createTOC();
to generate table of content in poi word(XWPF), and using addCustomHeadingStyle(doc, ChapterLvl.LVL_1.style, 1);
to generate headings Content, dotted line and page number. But I want to set different heading level's headings Content have different font size,font color, bold, and dotted line and page number have same style with its corresponding heading content, like the picture attachment, can someone give me some advice how to do that?
private static void addCustomHeadingStyle(XWPFDocument docxDocument, String strStyleId, int headingLevel) {
CTStyle ctStyle = CTStyle.Factory.newInstance();
ctStyle.setStyleId(strStyleId);
CTString styleName = CTString.Factory.newInstance();
styleName.setVal(strStyleId);
ctStyle.setName(styleName);
CTDecimalNumber indentNumber = CTDecimalNumber.Factory.newInstance();
indentNumber.setVal(BigInteger.valueOf(headingLevel));
ctStyle.setUiPriority(indentNumber);
CTOnOff onoffnull = CTOnOff.Factory.newInstance();
ctStyle.setUnhideWhenUsed(onoffnull);
ctStyle.setQFormat(onoffnull);
CTPPr ppr = CTPPr.Factory.newInstance();
ppr.setOutlineLvl(indentNumber);
ctStyle.setPPr(ppr);
XWPFStyle style = new XWPFStyle(ctStyle);
XWPFStyles styles = docxDocument.createStyles();
style.setType(STStyleType.PARAGRAPH);
styles.addStyle(style);
}
您的许多问题似乎都与XWPF有关.这是一个不完整的API.您可以阅读该规范以确定如何做API中没有提到的事情,然后有可能将其捐赠给社区.规范是此处. Apache POI项目使用第一版架构.我发现第1、3和4部分最有用.
A lot of your questions seem to be about XWPF. This is an incomplete API. You could read the spec to determine how to do things not surfaced in the API, and then potentially donate it back to the community. The specs are here. The Apache POI project uses the first edition schema. I find that Parts 1, 3, and 4 are the most useful.
对于这个特定的问题,使用doc.createTOC()
可以得到想要的东西吗?你得到什么?它是否位于文档中的适当位置?关于SOC,这里还有其他问题. x
是TOC级别.
As to this specific question, are you getting what you want with doc.createTOC()
? What are you getting? Is it located in the appropriate place in the document? There are other questions concerning TOC here on SO. This one in particular may help. If you need additional behaviors, the specs mentioned above contain more switches for the TOC field such as custom header styles to be included. The style of the TOC levels can be set by modifying the appropriate TOCx style where x
is the TOC level.