Olá,
Estou tendo problemas em gerar um relatório em excel pelo jasper;
acontece que ele gera o arquivo, porém quando abro o mesmo ele retorna o erro “Erro no arquivo: os dados podem ter sido perdidos” e abre em branco.
O código que testei peguei aqui no fórum, mas não encontrei a solução em nenhum lugar.
Quem tiver alguma idéia, agradeço mto.
O post que vi foi esse: http://www.guj.com.br/posts/list/37439.java
Meu código
[code] OutputStream output = new FileOutputStream(new File("C:/relatorio.xls"));
ByteArrayOutputStream xlsReport = new ByteArrayOutputStream();
byte bytes[] = new byte[10];
// exportação para excel
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, new JasperPrint());
exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, xlsReport);
exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_FILE, "C:/");
exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
try {
exporterXLS.exportReport();
// converte para bytes
bytes = xlsReport.toByteArray();
xlsReport.close();
// grava os bytes na saída
output.write(bytes, 0, bytes.length);
output.flush();
output.close();
} catch (Exception e) {
e.printStackTrace();
}[/code]
abs