采用apache 【POI】 框架生成excel文件
2017-02-20 17:38
351 查看
public static void CreateBugFile(String fileName, String bussinessNo, String projectPath) throws Exception {
File bugFile = new File(fileName + ".xls");
File file = new File(projectPath);
String[] titles = { "代码变更说明", "所属子系统", "代码路径", "修改人", "业务单号", "备注" };
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("代码导入");
HSSFCellStyle hssfCellStyle = workbook.createCellStyle();
hssfCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
hssfCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
hssfCellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
hssfCellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
hssfCellStyle.setVerticalAlignment(HSSFCellStyle.ALIGN_LEFT);
// hssfCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
// hssfCellStyle.setRightBorderColor(HSSFCellStyle.BORDER_THIN);
// hssfCellStyle.setLeftBorderColor(HSSFCellStyle.BORDER_THIN);
HSSFRow hssfRow = sheet.createRow(0);
for (int i = 0, j = titles.length; i < j; i++) {
HSSFCell hssfCell = hssfRow.createCell(i);
if (i == 2) {
sheet.setColumnWidth(i, 10000);
} else {
sheet.setColumnWidth(i, 5000);
}
hssfCell.setCellValue(titles[i].trim());
hssfCell.setCellStyle(hssfCellStyle);
}
for (int i = 0; i < list.size(); i++) {
HSSFRow hssfRow2 = sheet.createRow(i + 1);
for (int m = 0; m < 6; m++) {
HSSFCell hssfCell = hssfRow2.createCell(m);
if (m == 0) {
sheet.setColumnWidth(m, 5000);
hssfCell.setCellValue(codeChangeDesc.trim());
} else if (m == 1) {
sheet.setColumnWidth(m, 5000);
hssfCell.setCellValue(childSys.trim());
} else if (m == 2) {
sheet.setColumnWidth(m, 10000);
hssfCell.setCellValue(list.get(i).toString().trim());
} else if (m == 3) {
sheet.setColumnWidth(m, 5000);
hssfCell.setCellValue(updater.trim());
} else if (m == 4) {
sheet.setColumnWidth(m, 5000);
hssfCell.setCellValue(bussinessNo.trim());
} else if (m == 5) {
sheet.setColumnWidth(m, 5000);
hssfCell.setCellValue(remark.trim());
}
// sheet.setColumnWidth(m, 5000);
hssfCell.setCellStyle(hssfCellStyle);
}
}
FileOutputStream fileOutputStream = new FileOutputStream(bugFile);
workbook.write(fileOutputStream);
fileOutputStream.close();
}
File bugFile = new File(fileName + ".xls");
File file = new File(projectPath);
String[] titles = { "代码变更说明", "所属子系统", "代码路径", "修改人", "业务单号", "备注" };
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("代码导入");
HSSFCellStyle hssfCellStyle = workbook.createCellStyle();
hssfCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
hssfCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
hssfCellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
hssfCellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
hssfCellStyle.setVerticalAlignment(HSSFCellStyle.ALIGN_LEFT);
// hssfCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
// hssfCellStyle.setRightBorderColor(HSSFCellStyle.BORDER_THIN);
// hssfCellStyle.setLeftBorderColor(HSSFCellStyle.BORDER_THIN);
HSSFRow hssfRow = sheet.createRow(0);
for (int i = 0, j = titles.length; i < j; i++) {
HSSFCell hssfCell = hssfRow.createCell(i);
if (i == 2) {
sheet.setColumnWidth(i, 10000);
} else {
sheet.setColumnWidth(i, 5000);
}
hssfCell.setCellValue(titles[i].trim());
hssfCell.setCellStyle(hssfCellStyle);
}
for (int i = 0; i < list.size(); i++) {
HSSFRow hssfRow2 = sheet.createRow(i + 1);
for (int m = 0; m < 6; m++) {
HSSFCell hssfCell = hssfRow2.createCell(m);
if (m == 0) {
sheet.setColumnWidth(m, 5000);
hssfCell.setCellValue(codeChangeDesc.trim());
} else if (m == 1) {
sheet.setColumnWidth(m, 5000);
hssfCell.setCellValue(childSys.trim());
} else if (m == 2) {
sheet.setColumnWidth(m, 10000);
hssfCell.setCellValue(list.get(i).toString().trim());
} else if (m == 3) {
sheet.setColumnWidth(m, 5000);
hssfCell.setCellValue(updater.trim());
} else if (m == 4) {
sheet.setColumnWidth(m, 5000);
hssfCell.setCellValue(bussinessNo.trim());
} else if (m == 5) {
sheet.setColumnWidth(m, 5000);
hssfCell.setCellValue(remark.trim());
}
// sheet.setColumnWidth(m, 5000);
hssfCell.setCellStyle(hssfCellStyle);
}
}
FileOutputStream fileOutputStream = new FileOutputStream(bugFile);
workbook.write(fileOutputStream);
fileOutputStream.close();
}
相关文章推荐
- 教你如何利用POI和JFreeChart框架实现生成Excel文件(生成 统计图)
- 教你如何利用POI和JFreeChart框架实现生成Excel文件(生成 统计图)
- 利用apache的poi生成可供客户端下载的excel文件
- org.apache.poi包简单解析Excel文件
- poi生成excel文件中文乱码问题
- (6)POI生成Excel文件
- [置顶] 利用apache的poi来读取海量两种格式的Excel文件
- poi框架如何生成加密的EXCEL
- iMOOC学习笔记:Java的Excel读写操作入门实践-利用POI生成Excel文件(一)
- apache---poi读取和创建excel文件
- POI生成excel文件,自定义单元格颜色
- poi生成Excel文件【带样式和格式】
- 用POI生成excel文件
- 使用poi生成Excel文件
- 使用POI 将数据库中的数据生成Excel文件并下载
- 用poi生成自动筛选的Excel文件
- 使用POI生成Excel文件
- POI通过读取Excel模板生成Excel文件
- POI3.10读取Excel模板填充数据后生成新的Excel文件
- 使用POI生成Excel文件