本文整理汇总了Java中org.apache.poi.xwpf.usermodel.XWPFRun.setFontSize方法的典型用法代码示例。如果您正苦于以下问题:Java XWPFRun.setFontSize方法的具体用法?Java XWPFRun.setFontSize怎么用?Java XWPFRun.setFontSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.xwpf.usermodel.XWPFRun
的用法示例。
在下文中一共展示了XWPFRun.setFontSize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: SetFontStyle
import org.apache.poi.xwpf.usermodel.XWPFRun; //导入方法依赖的package包/类
private void SetFontStyle(XWPFRun run) {
run.setFontFamily("Calibri");
run.setFontSize(20);
}
示例4: saveStylesToDocxFile
import org.apache.poi.xwpf.usermodel.XWPFRun; //导入方法依赖的package包/类
/**
* ����text��������ʽ��docx��ʽ�ļ�
*/
@SuppressWarnings("deprecation")
public void saveStylesToDocxFile(StyledText text, XWPFDocument document) {
for (int i = 0; i < text.getLineCount(); ++i) {
int lineOffset = text.getOffsetAtLine(i);
String lineText = text.getLine(i);
XWPFParagraph paragraph = document.createParagraph();
paragraph.setFirstLineIndent(text.getIndent());
int lineAlignment = text.getLineAlignment(i);
switch (lineAlignment) {
case SWT.RIGHT:
paragraph.setAlignment(ParagraphAlignment.RIGHT);
break;
case SWT.CENTER:
paragraph.setAlignment(ParagraphAlignment.CENTER);
break;
}
// ����ÿһ�����ÿ���ַ�
for (int a = lineOffset; a < lineOffset + lineText.length(); ++a) {
StyleRange charStyle = text.getStyleRangeAtOffset(a);
String charText = text.getText(a, a);
XWPFRun run = paragraph.createRun();
run.setText(charText);
String fontname = null;
int fontsize = 0;
if (charStyle != null) {
// Color background = charStyle.background;
// Color foreground = charStyle.foreground;
if (charStyle.font != null) {
fontname = charStyle.font.getFontData()[0].getName();
if (b.text != null && text.equals(b.text))
fontsize = b.getFontRealSize(charStyle.font.getFontData()[0].getHeight());
else
fontsize = text.getFont().getFontData()[0].getHeight();
}
int fontstyle = charStyle.fontStyle;
switch (fontstyle) {
case SWT.BOLD:
run.setBold(true);
break;
case SWT.ITALIC:
run.setItalic(true);
break;
case SWT.BOLD | SWT.ITALIC:
run.setBold(true);
run.setItalic(true);
break;
}
run.setStrike(charStyle.strikeout);
if (charStyle.underline)
run.setUnderline(UnderlinePatterns.SINGLE);
run.setFontFamily(fontname, FontCharRange.eastAsia);
run.setFontSize(fontsize);
}
}
}
}
示例5: createDocument
import org.apache.poi.xwpf.usermodel.XWPFRun; //导入方法依赖的package包/类
@Override
public void createDocument(String documentName, String content) throws CitizenException {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph pg = doc.createParagraph();
XWPFRun run = pg.createRun();
run.setFontFamily("Calibri");
run.setFontSize(20);
run.setText(content);
try {
FileOutputStream out = new FileOutputStream(FILE_PATH+documentName+".docx");
doc.write(out);
out.close();
doc.close();
} catch (IOException e) {
throw new CitizenException("Error al generar documento word" +
" ["+ FILE_PATH+documentName+".docx] | ["+this.getClass().getName()+"]");
}
}