//去除目錄文字藍色樣式以及文字下方藍色下劃線for(FieldStart field: (Iterable<FieldStart>)doc.getChildNodes(NodeType.FIELD_START, true)){if (field.getFieldType() == FieldType.FIELD_HYPERLINK){FieldHyperlink hyperlink = (FieldHyperlink)field.getField();//判斷是否是目錄if (hyperlink.getSubAddress() != null && hyperlink.getSubAddress().startsWith("_Toc")) {//獲取目錄每行段落對象Paragraph tocItem = (Paragraph)field.getAncestor(NodeType.PARAGRAPH);if (tocItem != null) {//設置每行目錄樣式for (Run run : tocItem.getRuns()) {run.getFont().setColor(Color.BLACK);run.getFont().setBold(false);run.getFont().setUnderline(Underline.NONE);}}}}}
轉載于:https://www.cnblogs.com/haohj/p/10340518.html