本文整理汇总了Java中org.apache.poi.xwpf.usermodel.XWPFRun.setColor方法的典型用法代码示例。如果您正苦于以下问题:Java XWPFRun.setColor方法的具体用法?Java XWPFRun.setColor怎么用?Java XWPFRun.setColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.xwpf.usermodel.XWPFRun
的用法示例。
在下文中一共展示了XWPFRun.setColor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyMStyle
import org.apache.poi.xwpf.usermodel.XWPFRun; //导入方法依赖的package包/类
/**
* Apply the given style to the given run. Background color is not taken into account here since it does not apply to runs.
*
* @param run
* The run to style
* @param style
* The style to apply, can be <code>null</code>
*/
private void applyMStyle(XWPFRun run, MStyle style) {
if (style.getFontSize() != -1) {
run.setFontSize(style.getFontSize());
}
if (style.getFontModifiers() != -1) {
run.setBold((style.getFontModifiers() & MStyle.FONT_BOLD) != 0);
run.setItalic((style.getFontModifiers() & MStyle.FONT_ITALIC) != 0);
if ((style.getFontModifiers() & MStyle.FONT_UNDERLINE) != 0) {
run.setUnderline(UnderlinePatterns.SINGLE);
}
run.setStrikeThrough((style.getFontModifiers() & MStyle.FONT_STRIKE_THROUGH) != 0);
}
if (style.getForegroundColor() != null) {
run.setColor(hexColor(style.getForegroundColor()));
}
}
示例2: addRunError
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;
}
示例3: setRunMessage
import org.apache.poi.xwpf.usermodel.XWPFRun; //导入方法依赖的package包/类
/**
* Set the given message to the given {@link XWPFRun}.
*
* @param run
* the {@link XWPFRun}
* @param level
* the {@link ValidationMessageLevel}
* @param message
* the message
* @return the {@link TemplateValidationMessage}
*/
public static TemplateValidationMessage setRunMessage(XWPFRun run, ValidationMessageLevel level, String message) {
run.setText(message);
run.setBold(true);
run.setColor(getColor(level));
return new TemplateValidationMessage(level, message, run);
}