org.apache.poi.xssf.usermodel.XSSFRichTextString.applyFont()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(618)

本文整理了Java中org.apache.poi.xssf.usermodel.XSSFRichTextString.applyFont()方法的一些代码示例,展示了XSSFRichTextString.applyFont()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XSSFRichTextString.applyFont()方法的具体详情如下:
包路径:org.apache.poi.xssf.usermodel.XSSFRichTextString
类名称:XSSFRichTextString
方法名:applyFont

XSSFRichTextString.applyFont介绍

[英]Applies a font to the specified characters of a string.
[中]将字体应用于字符串的指定字符。

代码示例

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Sets the font of the entire string.
 * @param font          The font to use.
 */
public void applyFont(Font font) {
  String text = getString();
  applyFont(0, text.length(), font);
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Applies the specified font to the entire string.
 *
 * @param fontIndex  the font to apply.
 */
public void applyFont(short fontIndex) {
  XSSFFont font;
  if(styles == null) {
    font = new XSSFFont();
    font.setFontName("#" + fontIndex);
  } else {
    font = styles.getFontAt(fontIndex);
  }
  String text = getString();
  applyFont(0, text.length(), font);
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Applies a font to the specified characters of a string.
 *
 * @param startIndex    The start index to apply the font to (inclusive)
 * @param endIndex      The end index to apply the font to (exclusive)
 * @param fontIndex     The font to use.
 */
public void applyFont(int startIndex, int endIndex, short fontIndex) {
  XSSFFont font;
  if(styles == null) {
    //style table is not set, remember fontIndex and set the run properties later,
    //when setStylesTableReference is called
    font = new XSSFFont();
    font.setFontName("#" + fontIndex);
  } else {
    font = styles.getFontAt(fontIndex);
  }
  applyFont(startIndex, endIndex, font);
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Applies a font to the specified characters of a string.
 *
 * @param startIndex    The start index to apply the font to (inclusive)
 * @param endIndex      The end index to apply to font to (exclusive)
 * @param font          The index of the font to use.
 */
public void applyFont(int startIndex, int endIndex, Font font) {
  if (startIndex > endIndex)
    throw new IllegalArgumentException("Start index must be less than end index, but had " + startIndex + " and " + endIndex);
  if (startIndex < 0 || endIndex > length())
    throw new IllegalArgumentException("Start and end index not in range, but had " + startIndex + " and " + endIndex);
  if (startIndex == endIndex)
    return;
  if(st.sizeOfRArray() == 0 && st.isSetT()) {
    //convert <t>string</t> into a text run: <r><t>string</t></r>
    st.addNewR().setT(st.getT());
    st.unsetT();
  }
  String text = getString();
  XSSFFont xssfFont = (XSSFFont)font;
  TreeMap<Integer, CTRPrElt> formats = getFormatMap(st);
  CTRPrElt fmt = CTRPrElt.Factory.newInstance();
  setRunAttributes(xssfFont.getCTFont(), fmt);
  applyFont(formats, startIndex, endIndex, fmt);
  CTRst newSt = buildCTRst(text, formats);
  st.set(newSt);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * Sets the font of the entire string.
 * @param font          The font to use.
 */
public void applyFont(Font font) {
  String text = getString();
  applyFont(0, text.length(), font);
}

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

/**
 * Sets the font of the entire string.
 * @param font          The font to use.
 */
public void applyFont(Font font) {
  String text = getString();
  applyFont(0, text.length(), font);
}

代码示例来源:origin: stackoverflow.com

XSSFRichTextString rt1 = new XSSFRichTextString("Apache POI is");
rt1.applyFont(plainArial);
XSSFRichTextString rt2 = new XSSFRichTextString(" great!");
rt2.applyFont(boldArial);
String text = rt2.getString();

cell1.setCellValue(rt1.append(text, boldArial));

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * Applies the specified font to the entire string.
 *
 * @param fontIndex  the font to apply.
 */
public void applyFont(short fontIndex) {
  XSSFFont font;
  if(styles == null) {
    font = new XSSFFont();
    font.setFontName("#" + fontIndex);
  } else {
    font = styles.getFontAt(fontIndex);
  }
  String text = getString();
  applyFont(0, text.length(), font);
}

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

/**
 * Applies the specified font to the entire string.
 *
 * @param fontIndex  the font to apply.
 */
public void applyFont(short fontIndex) {
  XSSFFont font;
  if(styles == null) {
    font = new XSSFFont();
    font.setFontName("#" + fontIndex);
  } else {
    font = styles.getFontAt(fontIndex);
  }
  String text = getString();
  applyFont(0, text.length(), font);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * Applies a font to the specified characters of a string.
 *
 * @param startIndex    The start index to apply the font to (inclusive)
 * @param endIndex      The end index to apply the font to (exclusive)
 * @param fontIndex     The font to use.
 */
public void applyFont(int startIndex, int endIndex, short fontIndex) {
  XSSFFont font;
  if(styles == null) {
    //style table is not set, remember fontIndex and set the run properties later,
    //when setStylesTableReference is called
    font = new XSSFFont();
    font.setFontName("#" + fontIndex);
  } else {
    font = styles.getFontAt(fontIndex);
  }
  applyFont(startIndex, endIndex, font);
}

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

/**
 * Applies a font to the specified characters of a string.
 *
 * @param startIndex    The start index to apply the font to (inclusive)
 * @param endIndex      The end index to apply the font to (exclusive)
 * @param fontIndex     The font to use.
 */
public void applyFont(int startIndex, int endIndex, short fontIndex) {
  XSSFFont font;
  if(styles == null) {
    //style table is not set, remember fontIndex and set the run properties later,
    //when setStylesTableReference is called
    font = new XSSFFont();
    font.setFontName("#" + fontIndex);
  } else {
    font = styles.getFontAt(fontIndex);
  }
  applyFont(startIndex, endIndex, font);
}

代码示例来源:origin: stackoverflow.com

HSSFCell hssfCell = row.createCell(idx);
//rich text consists of two runs
HSSFRichTextString richString = new HSSFRichTextString( "Hello, World!" );
richString.applyFont( 0, 6, font1 );
richString.applyFont( 6, 13, font2 );
hssfCell.setCellValue( richString );

XSSFRichTextString s1 = new XSSFRichTextString("Apache POI");
s1.applyFont(boldArial);
cell1.setCellValue(s1);

代码示例来源:origin: org.apache.poi/poi-examples

font1.setBold(true);
font1.setColor(new XSSFColor(new java.awt.Color(255, 0, 0), wb.getStylesSource().getIndexedColors()));
rt.applyFont(0, 10, font1);
font2.setUnderline(XSSFFont.U_DOUBLE);
font2.setColor(new XSSFColor(new java.awt.Color(0, 255, 0), wb.getStylesSource().getIndexedColors()));
rt.applyFont(10, 19, font2);

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * Applies a font to the specified characters of a string.
 *
 * @param startIndex    The start index to apply the font to (inclusive)
 * @param endIndex      The end index to apply to font to (exclusive)
 * @param font          The index of the font to use.
 */
public void applyFont(int startIndex, int endIndex, Font font) {
  if (startIndex > endIndex)
    throw new IllegalArgumentException("Start index must be less than end index, but had " + startIndex + " and " + endIndex);
  if (startIndex < 0 || endIndex > length())
    throw new IllegalArgumentException("Start and end index not in range, but had " + startIndex + " and " + endIndex);
  if (startIndex == endIndex)
    return;
  if(st.sizeOfRArray() == 0 && st.isSetT()) {
    //convert <t>string</t> into a text run: <r><t>string</t></r>
    st.addNewR().setT(st.getT());
    st.unsetT();
  }
  String text = getString();
  XSSFFont xssfFont = (XSSFFont)font;
  TreeMap<Integer, CTRPrElt> formats = getFormatMap(st);
  CTRPrElt fmt = CTRPrElt.Factory.newInstance();
  setRunAttributes(xssfFont.getCTFont(), fmt);
  applyFont(formats, startIndex, endIndex, fmt);
  CTRst newSt = buildCTRst(text, formats);
  st.set(newSt);
}

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

/**
 * Applies a font to the specified characters of a string.
 *
 * @param startIndex    The start index to apply the font to (inclusive)
 * @param endIndex      The end index to apply to font to (exclusive)
 * @param font          The index of the font to use.
 */
public void applyFont(int startIndex, int endIndex, Font font) {
  if (startIndex > endIndex)
    throw new IllegalArgumentException("Start index must be less than end index.");
  if (startIndex < 0 || endIndex > length())
    throw new IllegalArgumentException("Start and end index not in range.");
  if (startIndex == endIndex)
    return;
  if(st.sizeOfRArray() == 0 && st.isSetT()) {
    //convert <t>string</t> into a text run: <r><t>string</t></r>
    st.addNewR().setT(st.getT());
    st.unsetT();
  }
  String text = getString();
  XSSFFont xssfFont = (XSSFFont)font;
  TreeMap<Integer, CTRPrElt> formats = getFormatMap(st);
  CTRPrElt fmt = CTRPrElt.Factory.newInstance();
  setRunAttributes(xssfFont.getCTFont(), fmt);
  applyFont(formats, startIndex, endIndex, fmt);
  CTRst newSt = buildCTRst(text, formats);
  st.set(newSt);
}

代码示例来源:origin: wuwz/ExcelKit

property.getComment());
Font commentFormatter = workbook.createFont();
xssfRichTextString.applyFont(commentFormatter);
cellComment.setString(xssfRichTextString);
cell.setCellComment(cellComment);

相关文章