Java Code Examples for org.apache.poi.ss.usermodel.Workbook#getFontAt()

The following examples show how to use org.apache.poi.ss.usermodel.Workbook#getFontAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StylerHelper.java    From autopoi with Apache License 2.0 5 votes vote down vote up
private void prontFonts(Workbook wb) {
	for (short i = 0, le = wb.getNumberOfFonts(); i <= le; i++) {
		Font font = wb.getFontAt(i);
		out.format(".%s .%s {%n", DEFAULTS_CLASS, "font_" + i + "_" + cssRandom);
		fontStyle(font);
		out.format("}%n");
	}

}
 
Example 2
Source File: CellValueHelper.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * O7 版本坑爹bug
 * 
 * @param wb
 */
private void cacheFontInfo(Workbook wb) {
	for (short i = 0, le = wb.getNumberOfFonts(); i < le; i++) {
		Font font = wb.getFontAt(i);
		fontCache.put(font.getBoldweight() + "_" + font.getItalic() + "_" + font.getFontName() + "_" + font.getFontHeightInPoints() + "_" + font.getColor(), font.getIndex() + "");
	}

}
 
Example 3
Source File: StylerHelper.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
private void prontFonts(Workbook wb) {
	for (short i = 0, le = wb.getNumberOfFonts(); i <= le; i++) {
		Font font = wb.getFontAt(i);
		out.format(".%s .%s {%n", DEFAULTS_CLASS, "font_" + i + "_" + cssRandom);
		fontStyle(font);
		out.format("}%n");
	}

}
 
Example 4
Source File: CellValueHelper.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * O7 版本坑爹bug
 * 
 * @param wb
 */
private void cacheFontInfo(Workbook wb) {
	for (short i = 0, le = wb.getNumberOfFonts(); i < le; i++) {
		Font font = wb.getFontAt(i);
		fontCache.put(font.getBoldweight() + "_" + font.getItalic() + "_" + font.getFontName() + "_" + font.getFontHeightInPoints() + "_" + font.getColor(), font.getIndex() + "");
	}

}
 
Example 5
Source File: SheetUtil.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get default character width using the Workbook's default font
 *
 * @param wb the workbook to get the default character width from
 * @return default character width in pixels
 */
@Internal
public static int getDefaultCharWidth(final Workbook wb) {
    Font defaultFont = wb.getFontAt((short) 0);

    AttributedString str = new AttributedString(String.valueOf(defaultChar));
    copyAttributes(defaultFont, str, 0, 1);
    TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext);
    return (int) layout.getAdvance();
}
 
Example 6
Source File: StylerHelper.java    From easypoi with Apache License 2.0 5 votes vote down vote up
private void prontFonts(Workbook wb) {
    for (short i = 0, le = wb.getNumberOfFonts(); i <= le; i++) {
        Font font = wb.getFontAt(i);
        out.format(".%s .%s {%n", DEFAULTS_CLASS, "font_" + i + "_" + cssRandom);
        fontStyle(font);
        out.format("}%n");
    }

}
 
Example 7
Source File: CellValueHelper.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * O7 版本坑爹bug
 * @param wb
 */
private void cacheFontInfo(Workbook wb) {
    for (short i = 0, le = wb.getNumberOfFonts(); i < le; i++) {
        Font font = wb.getFontAt(i);
        fontCache.put(font.getBoldweight() + "_" + font.getItalic() + "_" + font.getFontName()
                      + "_" + font.getFontHeightInPoints() + "_" + font.getColor(),
            font.getIndex() + "");
    }

}
 
Example 8
Source File: ExcelFontFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Constructor for ExcelFontFactory.
 *
 * @param workbook
 *          the workbook.
 */
public ExcelFontFactory( final Workbook workbook, final ExcelColorProducer colorProducer ) {
  if ( workbook == null ) {
    throw new NullPointerException();
  }
  if ( colorProducer == null ) {
    throw new NullPointerException();
  }

  this.fonts = new HashMap<HSSFFontWrapper, Font>();
  this.workbook = workbook;

  // read the fonts from the workbook ...
  // Funny one: Please note that the layout will be broken if the first
  // font is not 'Arial 10'.
  final short numberOfFonts = this.workbook.getNumberOfFonts();
  for ( int i = 0; i < numberOfFonts; i++ ) {
    final Font font = workbook.getFontAt( (short) i );
    this.fonts.put( new HSSFFontWrapper( font ), font );
  }

  // add the default font
  // this MUST be the first one, that is created.
  // oh, I hate Excel ...
  final HSSFFontWrapper wrapper =
      new HSSFFontWrapper( "Arial", (short) 10, false, false, false, false, colorProducer
          .getNearestColor( Color.black ) );
  getExcelFont( wrapper );
}