Java Code Examples for org.apache.poi.xssf.usermodel.XSSFFont#setFontHeight()

The following examples show how to use org.apache.poi.xssf.usermodel.XSSFFont#setFontHeight() . 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: CommonsUtils.java    From czy-nexus-commons-utils with Apache License 2.0 5 votes vote down vote up
/**
 * 大标题样式
 *
 * @param wb
 * @param cell
 * @param sxssfRow
 */
public static void setLabelStyles(SXSSFWorkbook wb, Cell cell, SXSSFRow sxssfRow) {
    CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(HorizontalAlignment.CENTER);
    cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    sxssfRow.setHeight((short) (399 * 2));
    XSSFFont font = (XSSFFont) wb.createFont();
    font.setFontName("宋体");
    font.setFontHeight(16);
    cellStyle.setFont(font);
    cell.setCellStyle(cellStyle);
}
 
Example 2
Source File: CommonsUtils.java    From czy-nexus-commons-utils with Apache License 2.0 5 votes vote down vote up
/**
 * 默认样式
 *
 * @param cellStyle
 * @param font
 * @return
 * @Parm
 */
public static void setStyle(CellStyle cellStyle, XSSFFont font,Integer fontSize) {
    cellStyle.setAlignment(HorizontalAlignment.CENTER);
    cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    font.setFontName("宋体");
    cellStyle.setFont(font);
    font.setFontHeight(fontSize);
    setBorder(cellStyle, true);
}
 
Example 3
Source File: ExcelUtil.java    From roncoo-jui-springboot with Apache License 2.0 5 votes vote down vote up
/**
 * 设置表头的单元格样式
 * 
 * @return
 */
public XSSFCellStyle getHeadStyle() {
	// 创建单元格样式
	XSSFCellStyle cellStyle = wb.createCellStyle();
	// 设置单元格的背景颜色为淡蓝色
	cellStyle.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
	// 创建单元格内容显示不下时自动换行
	//cellStyle.setWrapText(true);
	// 设置单元格字体样式
	XSSFFont font = wb.createFont();
	// 设置字体加粗
	font.setFontName("宋体");
	font.setFontHeight((short) 200);
	cellStyle.setFont(font);
	return cellStyle;
}
 
Example 4
Source File: ExcelUtil.java    From roncoo-jui-springboot with Apache License 2.0 5 votes vote down vote up
/**
 * 设置表体的单元格样式
 * 
 * @return
 */
public XSSFCellStyle getBodyStyle() {
	// 创建单元格样式
	XSSFCellStyle cellStyle = wb.createCellStyle();
	// 创建单元格内容显示不下时自动换行
	//cellStyle.setWrapText(true);
	// 设置单元格字体样式
	XSSFFont font = wb.createFont();
	// 设置字体加粗
	font.setFontName("宋体");
	font.setFontHeight((short) 200);
	cellStyle.setFont(font);
	return cellStyle;
}
 
Example 5
Source File: CommonsUtils.java    From czy-nexus-commons-utils with Apache License 2.0 4 votes vote down vote up
/**
 * @param cell         Cell对象。
 * @param wb           SXSSFWorkbook对象。
 * @param fontSize     字体大小。
 * @param bold         是否加粗。
 * @param center       是否左右上下居中。
 * @param isBorder     是否忽略边框
 * @param leftBoolean  左对齐
 * @param rightBoolean 右对齐
 * @param height       行高
 */
public static void setExcelStyles(Cell cell, SXSSFWorkbook wb, SXSSFRow sxssfRow, Integer fontSize, Boolean bold, Boolean center, Boolean isBorder, Boolean leftBoolean,
                                  Boolean rightBoolean, Integer fontColor, Integer height) {
    CellStyle cellStyle = cell.getRow().getSheet().getWorkbook().createCellStyle();
    //保证了既可以新建一个CellStyle,又可以不丢失原来的CellStyle 的样式
    cellStyle.cloneStyleFrom(cell.getCellStyle());
    //左右居中、上下居中
    if (center != null && center) {
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    }
    //右对齐
    if (rightBoolean != null && rightBoolean) {
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setAlignment(HorizontalAlignment.RIGHT);
    }
    //左对齐
    if (leftBoolean != null && leftBoolean) {
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setAlignment(HorizontalAlignment.LEFT);
    }
    //是否忽略边框
    if (isBorder != null && isBorder) {
        setBorderColor(cellStyle, isBorder);
    }
    //设置单元格字体样式
    XSSFFont font = (XSSFFont) wb.createFont();
    if (bold != null && bold) {
        font.setBold(bold);
    }
    //行高
    if (height != null) {
        sxssfRow.setHeight((short) (height * 2));
    }
    font.setFontName("宋体");
    font.setFontHeight(fontSize == null ? 12 : fontSize);
    cellStyle.setFont(font);
    //   点击可查看颜色对应的值: BLACK(8), WHITE(9), RED(10),
    font.setColor(IndexedColors.fromInt(fontColor == null ? 8 : fontColor).index);
    cell.setCellStyle(cellStyle);
}