public void exportToExcel() {
try {
ArrayList list = this.getSelectedCourseStudentsTableData();
System.out.println("=============size:" + list.size());
if (list != null && list.size() > 0) {
Long tp = new Long(System.currentTimeMillis());
String path = getApplicationBean().getFilePath()
+ "printfiles/" + tp.toString() + ".xls";
String name=path.substring(path.lastIndexOf('/')+1,path.length());
OutputStream outf = new FileOutputStream(path);
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("StudentCource");
sheet.setColumnWidth((short)0,(short)4000); //设置单元格的长度
sheet.setColumnWidth((short)3,(short)4000);
sheet.setColumnWidth((short)5,(short)6000);
sheet.setColumnWidth((short)6,(short)6000);
sheet.setHorizontallyCenter(true);
HSSFRow row1 = sheet.createRow(0);
HSSFCell cell1 = row1.createCell((short) 0);
cell1.setEncoding(HSSFCell.ENCODING_UTF_16);// 设置编码
cell1.setCellValue("学号");
cell1 = row1.createCell((short) 1);
cell1.setEncoding(HSSFCell.ENCODING_UTF_16);// 设置编码
cell1.setCellValue("姓名");
cell1 = row1.createCell((short) 2);
cell1.setEncoding(HSSFCell.ENCODING_UTF_16);// 设置编码
cell1.setCellValue("性别");
cell1 = row1.createCell((short) 3);
cell1.setEncoding(HSSFCell.ENCODING_UTF_16);// 设置编码
cell1.setCellValue("学生类别");
cell1 = row1.createCell((short) 4);
cell1.setEncoding(HSSFCell.ENCODING_UTF_16);// 设置编码
cell1.setCellValue("年级");
cell1 = row1.createCell((short) 5);
cell1.setEncoding(HSSFCell.ENCODING_UTF_16);// 设置编码
cell1.setCellValue("所属学院");
cell1 = row1.createCell((short) 6);
cell1.setEncoding(HSSFCell.ENCODING_UTF_16);// 设置编码
cell1.setCellValue("所学专业");
ArrayList selectedCourseStudentslist = this
.getSelectedCourseStudentsTableData();
for (int i = 0; i < selectedCourseStudentslist.size(); i++) {
HSSFRow row = sheet.createRow(i+1);
PgtStatusInfo pgtStatusInfo = (PgtStatusInfo) selectedCourseStudentslist
.get(i);
HSSFCell cell = row.createCell((short) 0);
cell.setCellValue(pgtStatusInfo.getStudentNo());
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(pgtStatusInfo.getName());
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(pgtStatusInfo.getSexCn());
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(pgtStatusInfo.getPgtTypeCn());
cell = row.createCell((short) 4);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(pgtStatusInfo.getGradeCn());
cell = row.createCell((short) 5);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(pgtStatusInfo.getBelongDeptCn());
cell = row.createCell((short) 6);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(pgtStatusInfo.getSpeCn());
}
wb.write(outf);
outf.close();
this.excelLink ="./files/printfiles/" + name;
this.excelFileLinkVisible = true;
this.outputFileLinkVisible = false;
} else {
getApplicationBean().addMessage(FacesMessage.SEVERITY_INFO,
"导出excel内容为空!", null);
}
} catch (Exception e) {
getApplicationBean().addMessage(FacesMessage.SEVERITY_ERROR,
"导出excel操作失败!", e.getMessage());
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lgq_0714/archive/2009/09/23/4582502.aspx
分享到:
相关推荐
1、java解析读取excel文件中的数据,并写入数据库。 2、java读取数据库数据,并导出为excel文件。 3、README.md中有详细的操作步骤示例。 使用说明: 1. 先使用postman导入:other/excel相关.postman_collection....
java 数据库 导出 excel
java实现mysql数据库的表导出到excel文件,已经基本的demo包含jar包,可以导入的eclipse里面。比较好用吧
Java实现excel文档数据导入数据库、导出excel
使用Hibernate操作数据库,将数据库的表数据导出到Excel文件中
Java+MySQL+将数据导入到Excel中,Java将Excel中的数据导入到MySQL数据库中,
JAVA实现数据库数据导入导出到Excel(POI)所需jar包
SpringBootMybatis+poi+Thymeleaf实现excel文件数据导入到数据库以及从数据库将数据导出成excel
jsp+Servlet实现的最简单的Excel表导入导出数据库的操作
支持从数据库中查询到数据,以多级表头形式导入到Excel文件中。比如:一级表头:学号、姓名、各科成绩。二级表头:语文、数学、英语(二级表头在各科成绩下面)。
Java实现数据库数据导出到excel,内有数据连接jar包,完整案例
阿里的EasyExcel+Mysql方式实现数据库数据导出生成excel,将excle表里面的数据保存到数据库
struts 中用一action将数据库中的内容导出到excel
可以将excel中的内容导入到mssql数据库中,也可以将MSSQL中的数据导出到Excel中.在导入时还可选择字段进行导入,并且原程序全部公开
获取通话记录文件格式vcf的转化,JAVA实现数据库数据导入/导出到Excel(POI)
java实现Excel数据导入到数据库,如果数据库中存在就更新。 数据库数据导入到Excel表中。 支持excel导库和反向导出。
基于Java Excel API的数据库数据导入导出方法研究与实现.pdf
用Java实现的Excel的导入导出,简洁明了,高质量代码。
springboot+mybatis+pol实现excel文件数据导入到数据库以及从数据库将数据导出成excel
java swing 导出Jtable里面的数据到excel,不用拷贝代码,直接粘贴代码