poi 创建 Excel

来源:互联网 发布:家庭网络组建 编辑:程序博客网 时间:2024/05/23 17:54

 实例地址: http://download.csdn.net/detail/ht_00001/9520917

/**创建文件*/
FileOutputStream fileOutput = new FileOutputStream(path);
Workbook wb =null;
if(path.endsWith(".xls")){
wb = new HSSFWorkbook();
}else if(path.endsWith(".xlsx")){
wb = new XSSFWorkbook();
}
/**创建Sheet*/
Sheet sheet1 = wb.createSheet("sheet1");

String safeName = WorkbookUtil.createSafeSheetName("[0'Brien's sales*?]");
Sheet  sheet2 = wb.createSheet(safeName);
CreationHelper createHelper = wb.getCreationHelper();

/**创建行*/
Row row = sheet1.createRow(0);
/**创建单元格*/
Cell cell = row.createCell(0);
/**单元格赋值*/
cell.setCellValue(0);

row.createCell(1).setCellValue(1.2);
/**设置样式*/
CellStyle style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
/**给单元格设置样式*/
row.createCell(1).setCellStyle(style);

0 0
原创粉丝点击