81,090
社区成员
发帖
与我相关
我的任务
分享
public ActionForward export (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
List resultList = new ArrayList();
resultList.add(" ");
OutputStream os = null;
try {
os = response.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
response.reset();// 清空输出流
response.setHeader("Content-disposition", "attachment; filename=Result.xls");// 设定输出文件头
response.setContentType("msexcel");// 定义输出类型
exportUser( resultList, os );
return null;
}
// 导出到 xls
public static int exportUser( List list, OutputStream os ) {
try {
// FileOutputStream os = new FileOutputStream("c:\\test.xls");
WritableWorkbook wwb = Workbook.createWorkbook( os );
WritableSheet ws = wwb.createSheet("导出", 0);
// 设定指定列的宽度
ws.setColumnView(0, 15);
ws.setColumnView(1, 15);
ws.setColumnView(2, 15);
// 设定标签颜色
WritableFont wf_merge = new WritableFont(WritableFont.ARIAL, 10,
WritableFont.NO_BOLD, false,
UnderlineStyle.SINGLE_ACCOUNTING, Colour.RED);
WritableCellFormat wff_merge = new WritableCellFormat( wf_merge);
wff_merge.setBackground( Colour.WHITE );
// 设置首行标题栏
Label label10 = new Label(0, 0, "123", wff_merge);
ws.addCell(label10);
Label label20 = new Label(1, 0, "123", wff_merge);
ws.addCell(label20);
Label label30 = new Label(2, 0, "123", wff_merge);
ws.addCell(label30);
wwb.write();
wwb.close();
os.close();
} catch (IOException e) {
return 1;
} catch (Exception e) {
return 1;
}
return 0;
}