67,538
社区成员
发帖
与我相关
我的任务
分享
//导出用户信息
private void exportPriceFundTaxPayers(Collection col, HttpServletResponse response) throws Exception {
String currentDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
String fileName = "%E4%BA%BA" + currentDate + ".xls";
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
response.setContentType("application/vnd.ms-excel;charset=GBK");
WritableWorkbook book = Workbook.createWorkbook(response.getOutputStream());
WritableSheet sheet = book.createSheet("sheet1", 0);
WritableCellFormat wcf = new WritableCellFormat();
wcf.setBorder(Border.ALL, BorderLineStyle.THIN);
int counter = 0;
int idx_sheet = 1;
if (col != null && col.size() > 0) {
for (Iterator it = col.iterator(); it.hasNext(); counter++) {
if (counter == 10000) {
sheet = book.createSheet("sheet" + (idx_sheet + 1), idx_sheet);
idx_sheet++;
counter = 0;
}
User user = (User) it.next();
sheet.addCell(new Label(0, counter, user.getName(), wcf));
sheet.addCell(new Label(1, counter, user.getAge(), wcf));
sheet.addCell(new Label(2, counter, user.getSex(), wcf));
}
book.write();
book.close();
} else {
sheet.addCell(new Label(2, 3, "没有找到用户信息!", wcf));
book.write();
book.close();
}
}