WritableWorkbook out = null;
try {
response.getServletResponse().reset();
((HttpServletResponse) response.getServletResponse()).setHeader("Content-Disposition", "attachment;filename=export.xls");
response.getServletResponse().setContentType("gbk");
response.getServletResponse().setCharacterEncoding("gbk");
response.getServletResponse().setContentType("application/vnd.ms-excel");
out = Workbook.createWorkbook(((HttpServletResponse) response.getServletResponse()).getOutputStream());
int sheetNum = 0;
WritableSheet sheet = out.createSheet("第1页", sheetNum);
Label labels = null;
String[] labea = { "员工唯一号", "员工姓名", "补差开始时间", "补差结束时间", "申报工资" };
for (int i = 0; i < labea.length; i++) {
labels = new Label(i, 0, labea[i]);
sheet.addCell(labels);
}
Label label = null;
for (int i = 0; i < beans.size(); i++) {
EmppostVo vo = (EmppostVo) beans.get(i);
String emp_code = vo.getEmp_code() == null ? "" : vo.getEmp_code();
String emp_name = vo.getEmp_name() == null ? "" : vo.getEmp_name();
String startDate = vo.getStart_month() == null ? "" : vo.getStart_month().substring(0, 11);
String endDate = vo.getEnd_month()== null ? "" : vo.getEnd_month().substring(0, 11);
String baseSalary = vo.getBase_salary()== null ? "" : vo.getBase_salary();
String[] strArr = { emp_code, emp_name, startDate, endDate,baseSalary};
for (int j = 0; j < strArr.length; j++) {
label = new Label(j, i + 1, strArr[j]);
sheet.addCell(label);
}
}
out.write();
} catch (RuntimeException e) {
e.printStackTrace();
}finally{
out.close();
}
java 操作 Excel,java导出excel,布布扣,bubuko.com
java 操作 Excel,java导出excel