采用apache 【POI】 框架生成excel文件
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了采用apache 【POI】 框架生成excel文件,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2261字,纯文字阅读大概需要4分钟。
内容图文
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();
}
本文出自 “一代宗师” 博客,请务必保留此出处http://765682.blog.51cto.com/755682/1899573
原文:http://765682.blog.51cto.com/755682/1899573
内容总结
以上是互联网集市为您收集整理的采用apache 【POI】 框架生成excel文件全部内容,希望文章能够帮你解决采用apache 【POI】 框架生成excel文件所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。