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

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

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

XSSFRichTextString.setRunAttributes介绍

[英]Copy font attributes from CTFont bean into CTRPrElt bean
[中]将字体属性从CTFont bean复制到CTRPrElt bean中

代码示例

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

protected void setStylesTableReference(StylesTable tbl){
  styles = tbl;
  if(st.sizeOfRArray() > 0) {
    //noinspection deprecation - for performance reasons!
    for (CTRElt r : st.getRArray()) {
      CTRPrElt pr = r.getRPr();
      if(pr != null && pr.sizeOfRFontArray() > 0){
        String fontName = pr.getRFontArray(0).getVal();
        if(fontName.startsWith("#")){
          int idx = Integer.parseInt(fontName.substring(1));
          XSSFFont font = styles.getFontAt(idx);
          pr.removeRFont(0);
          setRunAttributes(font.getCTFont(), pr);
        }
      }
    }
  }
}

代码示例来源: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.poi/poi-ooxml

/**
 * Append new text to this text run and apply the specify font to it
 *
 * @param text  the text to append
 * @param font  the font to apply to the appended text or <code>null</code> if no formatting is required
 */
public void append(String text, XSSFFont font){
  if(st.sizeOfRArray() == 0 && st.isSetT()) {
    //convert <t>string</t> into a text run: <r><t>string</t></r>
    CTRElt lt = st.addNewR();
    lt.setT(st.getT());
    preserveSpaces(lt.xgetT());
    st.unsetT();
  }
  CTRElt lt = st.addNewR();
  lt.setT(text);
  preserveSpaces(lt.xgetT());
  
  if (font != null) {
    CTRPrElt pr = lt.addNewRPr();
    setRunAttributes(font.getCTFont(), pr);
  }
}

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

@SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
protected void setStylesTableReference(StylesTable tbl){
  styles = tbl;
  if(st.sizeOfRArray() > 0) {
    for (CTRElt r : st.getRArray()) {
      CTRPrElt pr = r.getRPr();
      if(pr != null && pr.sizeOfRFontArray() > 0){
        String fontName = pr.getRFontArray(0).getVal();
        if(fontName.startsWith("#")){
          int idx = Integer.parseInt(fontName.substring(1));
          XSSFFont font = styles.getFontAt(idx);
          pr.removeRFont(0);
          setRunAttributes(font.getCTFont(), pr);
        }
      }
    }
  }
}

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

protected void setStylesTableReference(StylesTable tbl){
  styles = tbl;
  if(st.sizeOfRArray() > 0) {
    //noinspection deprecation - for performance reasons!
    for (CTRElt r : st.getRArray()) {
      CTRPrElt pr = r.getRPr();
      if(pr != null && pr.sizeOfRFontArray() > 0){
        String fontName = pr.getRFontArray(0).getVal();
        if(fontName.startsWith("#")){
          int idx = Integer.parseInt(fontName.substring(1));
          XSSFFont font = styles.getFontAt(idx);
          pr.removeRFont(0);
          setRunAttributes(font.getCTFont(), pr);
        }
      }
    }
  }
}

代码示例来源: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: org.openl.rules/org.openl.lib.poi.dev

/**
 * Append new text to this text run and apply the specify font to it
 *
 * @param text  the text to append
 * @param font  the font to apply to the appended text or <code>null</code> if no formatting is required
 */
public void append(String text, XSSFFont font){
  if(st.sizeOfRArray() == 0 && st.isSetT()) {
    //convert <t>string</t> into a text run: <r><t>string</t></r>
    CTRElt lt = st.addNewR();
    lt.setT(st.getT());
    preserveSpaces(lt.xgetT());
    st.unsetT();
  }
  CTRElt lt = st.addNewR();
  lt.setT(text);
  preserveSpaces(lt.xgetT());
  CTRPrElt pr = lt.addNewRPr();
  if(font != null) setRunAttributes(font.getCTFont(), pr);
}

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

/**
 * Append new text to this text run and apply the specify font to it
 *
 * @param text  the text to append
 * @param font  the font to apply to the appended text or <code>null</code> if no formatting is required
 */
public void append(String text, XSSFFont font){
  if(st.sizeOfRArray() == 0 && st.isSetT()) {
    //convert <t>string</t> into a text run: <r><t>string</t></r>
    CTRElt lt = st.addNewR();
    lt.setT(st.getT());
    preserveSpaces(lt.xgetT());
    st.unsetT();
  }
  CTRElt lt = st.addNewR();
  lt.setT(text);
  preserveSpaces(lt.xgetT());
  
  if (font != null) {
    CTRPrElt pr = lt.addNewRPr();
    setRunAttributes(font.getCTFont(), pr);
  }
}

相关文章