Java操作Excel(二)将数据库中的数据导出到Excel中
来源:互联网 发布:mac口红国内专柜价格 编辑:程序博客网 时间:2024/05/18 02:48
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());
}
}
- Java操作Excel(二)将数据库中的数据导出到Excel中
- Java操作Excel(二)将数据库中的数据导出到Excel中
- 将数据库中的数据导出到Excel中(直接导出到磁盘,Java方式)
- 将数据导出到Excel(java操作Excel)
- 将数据导出到Excel(java操作Excel)
- 将数据导出到Excel(java操作Excel)
- 将数据导出到Excel(java操作Excel)
- 将数据库中的数据导出到Excel和Doc中
- 将数据库中的数据导出到Excel中
- .net 将数据库中的数据导出到Excel表格中
- C#操作Excel,将DataGridView数据导出到Excel中
- C#操作Excel,将DataGridView数据导出到Excel中
- NPOI操作EXCEL 将Table中数据导出到Excel
- java将数据库中的数据导入到excel表中
- 将数据库里的数据导出到EXCEL中的方法
- 20160307 DataTableToExcel(将数据库中的数据导出到Excel表)
- 将数据库的数据导出到EXCEL中
- 将数据库的数据导出到Excel表中
- 只有“第四驾马车”才能拉动中国经济
- Format Specifiers for memo
- 把URL转换成绝对URL
- Java操作Excel(一)Poi简介
- 什么是BADI,如何从SAP中查找BADI?
- Java操作Excel(二)将数据库中的数据导出到Excel中
- 78 76
- Java操作Excel(三)将Excel中的数据批量的导入数据库
- Delphi分解模块的技术
- 开始记点东西吧……
- n73 电池“万能充”充电的问题
- 无言
- 仿照Sina的导航
- delphi中后缀名分别指代的文件和用处