De retour de document Excel à partir du Printemps Contrôleur à l'aide d'Apache POI

J'essaie d'envoyer un fichier Excel à l'utilisateur. D'une certaine façon mon fichier excel est corrompu, même si elle est vide. Quand j'ouvre le fichier Excel me dit que le fichier est corrompu.

Si je supprime

response.getOutputStream().write(excelService.exportEventsToCSV());

- Je obtenir un vide de fichier excel.

@RequestMapping(value = "/events/excel", method = RequestMethod.GET)
    public void getEventsAsExcel(HttpServletResponse response) {

        try {

            response.setHeader("Content-disposition", "attachment; filename=test.xls");
            response.getOutputStream().write(excelService.exportEventsToCSV());
        } catch (Exception e) {
            //TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

Ma génération XML est très simple. Tout simplement vide de document

@Override
public byte[] exportEventsToCSV() {
    try {

        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet worksheet = workbook.createSheet("POI Worksheet");
        HSSFCellStyle cellStyle = workbook.createCellStyle();


        workbook.write(fileOut);

        return workbook.getBytes();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

Merci de tous les conseils. Je pensais à Ressorts Excel point de vue, mais je ne veux pas d'un point de vue. Juste un fichier téléchargé.

OriginalL'auteur pethel | 2012-11-07