HSSFCellStyle样式详解

public final class HSSFCellStyle
extends java.lang.Object
implements CellStyle
High level representation of the style of a cell in a sheet of a workbook.
HSSFCellStyle是一个实现了CellStyle接口的类,用于工作簿的工作页中每个单元格的高级样式展示
下面给一个设置样式的简单示例:

// 生成一个样式
HSSFCellStyle style = workbook.createCellStyle();
// 设置这些样式
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//水平居中 
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中

 // 背景色
style.setFillForegroundColor(HSSFColor.YELLOW.index);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); 
style.setFillBackgroundColor(HSSFColor.YELLOW.index); 

// 设置边框
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setBorderTop(HSSFCellStyle.BORDER_THIN);  
// 自动换行  
style.setWrapText(true);  

// 生成一个字体
HSSFFont font = workbook.createFont();
font.setFontHeightInPoints((short) 10);
font.setColor(HSSFColor.RED.index);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setFontName("宋体");

// 把字体 应用到当前样式
style.setFont(font);

//style设置好后,为cell设置样式
cell.setCellStyle(style)//cell为已有的单元格

更多详细解释请看:
http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFCellStyle.html


版权声明:本文为jiajane原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。