我需要导出一个xls文件。我使用Spring MVC和Apache POI。 我不能下载xls文件....按照代码更好地解决。
我在javascript中使用此方法来调用控制器
this.exportExcel = function() {
$.get("exportar", function(data){
});
};
在我的控制器中,我将该类调用为builder xls
@RequestMapping(value = "/exportar")
public ModelAndView exportExcel(HttpServletResponse response) {
return new ModelAndView("excelView", "listForExcel", listDemanda);
}
使用构建器XLS
的类@Override
protected void buildExcelDocument(Map<String, Object> model,
HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception {
List<TB_Demanda> listForExcel = (List<TB_Demanda>)model.get("listForExcel");
System.out.println("entrou no excel builder");
HSSFSheet sheet = workbook.createSheet("Aba 1");
Row row = sheet.createRow(0);
Cell cell;
cell = row.createCell(0);
cell.setCellValue("Código");
cell = row.createCell(1);
cell.setCellValue("Descrição");
cell = row.createCell(2);
cell.setCellValue("Data de Inclusão");
cell = row.createCell(3);
cell.setCellValue("Data Prevista para Entrega");
cell = row.createCell(4);
cell.setCellValue("Situação");
cell = row.createCell(5);
cell.setCellValue("Fase");
int numCelula = 0;
int numLinha = 1;
for(TB_Demanda d : listForExcel) {
row = sheet.createRow(numLinha);
cell = row.createCell(numCelula++);
cell.setCellValue(d.getCodigoDemanda());
cell = row.createCell(numCelula++);
cell.setCellValue(d.getDescDemanda());
cell = row.createCell(numCelula++);
cell.setCellValue(Utils.dataFormatoPadrao(d.getDtInclusaoDemanda()));
cell = row.createCell(numCelula++);
cell.setCellValue(Utils.dataFormatoPadrao(d.getDtPrevistaEntrega()));
cell = row.createCell(numCelula++);
cell.setCellValue(d.getDescSituacaoEntrega());
cell = row.createCell(numCelula++);
cell.setCellValue(d.getDescTipoFase());
numCelula = 0;
numLinha++;
}
}
所以当我点击按钮导出时我无法进行下载。谁知道发生了什么?