Ext作excel导出,始终不弹出下载对话框(程序不报错)

解决方案 »

  1.   

    代码如下
    /** 设置响应头 **/
    public void setResponseHeader() {
    System.out.println("===>>>"+response);
    response.setContentType("application/octet-stream;charset=iso-8859-1");
    try {
    //System.out.println(fileName);
    response.setHeader("Content-Disposition", "attachment;filename="
    + java.net.URLEncoder.encode(this.fileName, "UTF-8"));
    // 客户端不缓存
    response.addHeader("Pargam", "no-cache");
    response.addHeader("Cache-Control", "no-cache");




    } catch (Exception ex) {
    ex.printStackTrace();
    } } /** 导出数据 **/
    public void exportExcel(OutputStream os) {
    Workbook workbook = null;
    if ("xls".equals(format)) {
    workbook = new HSSFWorkbook();
    }
    if ("xlsx".equals(format)) {
    workbook = new XSSFWorkbook();
    }
    Sheet sheet = workbook.createSheet("人员信息");
    Row row = sheet.createRow(0);
    row.createCell(0).setCellValue("培训ID");
    row.createCell(1).setCellValue("培训内容");
    row.createCell(2).setCellValue("培训负责人");
    list = this.iTblPeixunPlanInforService.getAll();
    for (int i = 0; i < list.size(); i++) {
    TblPeixunPlanInfor tblPeixunPlanInfor = list.get(i);
    row = sheet.createRow(i + 1);
    row.createCell(0).setCellValue(tblPeixunPlanInfor.getPeixunID());
    row.createCell(1).setCellValue(tblPeixunPlanInfor.getPeixunContent());
    row.createCell(2).setCellValue(tblPeixunPlanInfor.getPeixunFuzeren());
    }
    try {
    //os.write(113);
    workbook.write(os);
    } catch (Exception e) {
    e.printStackTrace();
    }
    } public String execute() {
    setResponseHeader();
    try {
    //System.out.println(response.getOutputStream());
    exportExcel(response.getOutputStream());
    response.getOutputStream().flush();
    response.getOutputStream().close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return null;
    }