2013-05-14 83 views
0

我在我的spring mvc3項目中使用Apache POI生成Excel表。該文件生成不帶.xls擴展名。如果我用.xls手動重命名同一個文件,數據生成的很好。這裏是我的代碼片斷::Excel中不添加擴展(APACHE POI)

@RequestMapping(value = "/download/") 
    public void downloadMerchantMiniStatement(final HttpServletResponse response, 
      @RequestParam(value = "fromDate", required = true) String fromDate, 
      @RequestParam(value = "toDate", required = true) String toDate, 
      @RequestParam(value = "status", required = false) String status 
      ) throws IOException { 

     String fileName = STATEMENT_REPORT_" + getDateString(new Date()) + ".xls"; 
     List<TransactionDTO> transactionDtos = excelService.getTransactionsForExcel(Status, DateUtil.convertStringToDate(fromDate), DateUtil.convertStringToDate(toDate)); 

     ByteArrayOutputStream excel = getExcelStatement(transactionDtos, fromDate, toDate, status); 
     excel.writeTo(response.getOutputStream()); 
     response.setContentType("application/excel"); 
     response.setHeader("Expires:", "0"); 
     response.setHeader("Content-Disposition", "attachment; filename=" + fileName); 
     response.getOutputStream().flush(); 
     response.getOutputStream().close(); 
    } 

回答

0

終於得到了解決,需要與response.setContentType("application/vnd.ms-excel");

,給出了一個標準格式輸出被替換的代碼response.setContentType("application/excel");