org.apache.poi.ss.usermodel.Font.getIndexAsInt()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(3.3k)|赞(0)|评价(0)|浏览(344)

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

Font.getIndexAsInt介绍

[英]get the index within the XSSFWorkbook (sequence within the collection of Font objects)
[中]获取XSSF工作簿中的索引(字体对象集合中的顺序)

代码示例

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

/**
 * Take a cell, and apply a font to it
 *
 * @param cell the cell to set the alignment for
 * @param font The Font that you want to set.
 * @throws IllegalArgumentException if <tt>font</tt> and <tt>cell</tt> do not belong to the same workbook
 */
public static void setFont(Cell cell, Font font) {
  // Check if font belongs to workbook
  Workbook wb = cell.getSheet().getWorkbook();
  final int fontIndex = font.getIndexAsInt();
  if (!wb.getFontAt(fontIndex).equals(font)) {
    throw new IllegalArgumentException("Font does not belong to this workbook");
  }
  // Check if cell belongs to workbook
  // (checked in setCellStyleProperty)
  setCellStyleProperty(cell, FONT, fontIndex);
}

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

/**
 * Set the font for this style
 *
 * @param font  a font object created or retrieved from the XSSFWorkbook object
 * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#createFont()
 * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#getFontAt(short)
 */
@Override
public void setFont(Font font) {
  if(font != null){
    long index = font.getIndexAsInt();
    this._cellXf.setFontId(index);
    this._cellXf.setApplyFont(true);
  } else {
    this._cellXf.setApplyFont(false);
  }
}

代码示例来源:origin: com.helger/ph-poi

/**
 * Set the index of the font to use. The font must have been previously
 * created via Workbook.createFont()!
 *
 * @param aFont
 *        The font to use. May not be <code>null</code>.
 * @return this
 */
@Nonnull
public ExcelStyle setFont (@Nonnull final Font aFont)
{
 ValueEnforcer.notNull (aFont, "Font");
 return setFontIndex (aFont.getIndexAsInt ());
}

代码示例来源:origin: com.phloc/phloc-poi

/**
 * Set the index of the font to use. The font must have been previously
 * created via Workbook.createFont()!
 *
 * @param aFont
 *        The font to use. May not be <code>null</code>.
 * @return this
 */
@Nonnull
public ExcelStyle setFont (@Nonnull final Font aFont)
{
 ValueEnforcer.notNull (aFont, "Font");
 return setFontIndex (aFont.getIndexAsInt ());
}

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

/**
 * Take a cell, and apply a font to it
 *
 * @param cell the cell to set the alignment for
 * @param font The Font that you want to set.
 * @throws IllegalArgumentException if <tt>font</tt> and <tt>cell</tt> do not belong to the same workbook
 */
public static void setFont(Cell cell, Font font) {
  // Check if font belongs to workbook
  Workbook wb = cell.getSheet().getWorkbook();
  final int fontIndex = font.getIndexAsInt();
  if (!wb.getFontAt(fontIndex).equals(font)) {
    throw new IllegalArgumentException("Font does not belong to this workbook");
  }
  // Check if cell belongs to workbook
  // (checked in setCellStyleProperty)
  setCellStyleProperty(cell, FONT, fontIndex);
}

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

/**
 * Set the font for this style
 *
 * @param font  a font object created or retrieved from the XSSFWorkbook object
 * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#createFont()
 * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#getFontAt(short)
 */
@Override
public void setFont(Font font) {
  if(font != null){
    long index = font.getIndexAsInt();
    this._cellXf.setFontId(index);
    this._cellXf.setApplyFont(true);
  } else {
    this._cellXf.setApplyFont(false);
  }
}

相关文章