SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
String filename = "a" + df.format(new Date()) + ".xls";
//File file=new File(filename);
try {
ServletOutputStream os = response.getOutputStream();
response.reset();
// 设置response的Header
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes()));
//response.addHeader("Content-Length", "" + file.length());
WritableWorkbook wb=Workbook.createWorkbook(os);
int count=list.size()/65535+1;
for(int i=1;i<=count;i++){
WritableSheet ws=wb.createSheet("sheet"+String.valueOf(i), i-1);
ws.addCell(new Label(0, 0, "标题"));
ws.addCell(new Label(1, 0, "姓名"));
ws.addCell(new Label(2, 0, "手机号"));
ws.addCell(new Label(3, 0, "咨询编号"));
ws.addCell(new Label(4, 0, "内容"));
//ws.addCell(new Label(0, 5, "回复内容"));
int row=1;
int col=0;
for(Content c:list){
if(row==65535) break;
ws.addCell(new Label(0, row, c.getContentExt().getTitle()));
ws.addCell(new Label(1, row, c.getAttr().get("name")));
ws.addCell(new Label(2, row, c.getAttr().get("phone")));
ws.addCell(new Label(3, row, c.getAttr().get("lawCode")));
ws.addCell(new Label(4, row, c.getContentTxt().getTxt()));
row++;
}
}
wb.write();
wb.close();
os.close();
response.flushBuffer();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RowsExceededException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}