天天看點

poi 擷取的字型大小同html字型大小,如何在poi word中設定内容表的字型樣式,包括字型顔色,字型大小和粗體?(How to set table of content's font style...

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);

}

poi 擷取的字型大小同html字型大小,如何在poi word中設定内容表的字型樣式,包括字型顔色,字型大小和粗體?(How to set table of content's font style...