日期:2014-05-20 浏览次数:20917 次
/**
* <一句话功能简述> 向EXl文件中写入一行
* <功能详细描述>
* @param wb HSSFWorkbook
* @param strings 写入的字符串
* @param lineNum 写入的行号
* @param isTitle [参数说明] 是否是title
* @see [类、类#方法、类#成员]
*/
public void writeLine(HSSFWorkbook wb, String[] strings, int lineNum,
boolean isTitle)
{
HSSFSheet sheet = null;
try
{
sheet = wb.getSheetAt(0);
}
catch (Exception e)
{
sheet = wb.createSheet("TaskzUpgradeReport");
}
HSSFRow hssfRow = sheet.createRow(lineNum);
HSSFCellStyle cellStyle1 = wb.createCellStyle();
if (isTitle)
{
//设置标题的背景色
cellStyle1.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
cellStyle1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
HSSFFont font2 = wb.createFont();
//设置标题的字体
final short fontCode2 = 0x64;
font2.setBoldweight(fontCode2);
cellStyle1.setFont(font2);
cellStyle1.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cellStyle1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cellStyle1.setBorderRight(HSSFCellStyle.BORDER_THIN);
cellStyle1.setBorderTop(HSSFCellStyle.BORDER_THIN);
}
//设置行高
final short height = 0x249;
hssfRow.setHeight(height);
int length = strings.length;
HSSFCell hssfCell = null;
for (int index = 0; index < length; index++)
{
// 创建列
hssfCell = hssfRow.createCell((short)index);
//此单元格设置列风格
hssfCell.setCellStyle(cellStyle1);
//为单元格赋值
hssfCell.setCellValue(new HSSFRichTextString(strings[index]));
sheet.setColumnWidth((short)index, COLUMN_WEITH);
}
}
------解决方案--------------------