概述
import org.apache.poi.xwpf.usermodel.XWPFRun; //导入方法依赖的package包/类
/**
* Inserts the given {@link TemplateValidationMessage} in a run next to the one of the given construct subject to the message.
*
* @param message
* the {@link TemplateValidationMessage} to insert
* the error message to insert in a run
* @param offset
* the offset in number of {@link XWPFRun} to insert after {@link TemplateValidationMessage#getLocation() message location}
* @return the number of inserted {@link XWPFRun}
*/
private int addRunError(TemplateValidationMessage message, int offset) {
int res = 0;
if (message.getLocation().getParent() instanceof XWPFParagraph) {
XWPFParagraph paragraph = (XWPFParagraph) message.getLocation().getParent();
final int basePosition = paragraph.getRuns().indexOf(message.getLocation()) + offset;
// separation run.
res++;
final String color = M2DocUtils.getColor(message.getLevel());
XWPFRun newBlankRun = paragraph.insertNewRun(basePosition + res);
newBlankRun.setText(BLANK_SEPARATOR);
res++;
final XWPFRun separationRun = paragraph.insertNewRun(basePosition + res);
separationRun.setText(LOCATION_SEPARATOR);
separationRun.setColor(color);
separationRun.setFontSize(ERROR_MESSAGE_FONT_SIZE);
final CTHighlight separationHighlight = separationRun.getCTR().getRPr().addNewHighlight();
separationHighlight.setVal(STHighlightColor.LIGHT_GRAY);
res++;
final XWPFRun messageRun = paragraph.insertNewRun(basePosition + res);
messageRun.setText(message.getMessage());
messageRun.setColor(color);
messageRun.setFontSize(ERROR_MESSAGE_FONT_SIZE);
final CTHighlight messageHighlight = messageRun.getCTR().getRPr().addNewHighlight();
messageHighlight.setVal(STHighlightColor.LIGHT_GRAY);
}
return res;
}
最后
以上就是热心裙子为你收集整理的java中setcolor_Java XWPFRun.setColor方法代码示例的全部内容,希望文章能够帮你解决java中setcolor_Java XWPFRun.setColor方法代码示例所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复