'apache poi add styles like setColor, setFontFamily etc ( to 2 different markers )
hello I'm new to apache poi, I have some problems, I would like to add types of styles to 2 different types of marker,
Here I show a part of my code where I only put a stylo in general. how would you separate it and add styles to each different marker?
public static void insertMark(XWPFDocument doc, String bookmarkName, String bookmarkValue) {
try {
List<XWPFParagraph> paraList = null;
Iterator<XWPFParagraph> paraIter = null;
XWPFParagraph para = null;
List<CTBookmark> bookmarkList = null;
Iterator<CTBookmark> bookmarkIter = null;
CTBookmark bookmark = null;
XWPFRun run = null;
Node nextNode = null;
paraList = doc.getParagraphs();
paraIter = paraList.iterator();
while (paraIter.hasNext()) {
para = paraIter.next();
bookmarkList = para.getCTP().getBookmarkStartList();
bookmarkIter = bookmarkList.iterator();
while (bookmarkIter.hasNext()) {
bookmark = bookmarkIter.next();
if (bookmark.getName().equals(bookmarkName)) {
run = para.createRun();
run.setColor("353993");
run.setFontFamily("Calibri");
run.setBold(true);
run.setFontSize(14);
run.setText(bookmarkValue);
nextNode = bookmark.getDomNode().getNextSibling();
while (!(nextNode.getNodeName().contains("bookmarkEnd"))) {
para.getCTP().getDomNode().removeChild(nextNode);
nextNode = bookmark.getDomNode().getNextSibling();
}
para.getCTP().getDomNode().insertBefore(
run.getCTR().getDomNode(),
nextNode);
}
}
}
}catch()...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
