Ao gerar um relatório em Excel, a planilha sai em branco.
Gerei o relatório em PDF para verificar se não era erro de banco, mas o relatório sai perfeitamente.
Segue o trecho do código que gera o relatório, tanto em Excel quanto em PDF.
public class Relatorio
{
private static Logger logger = Logger.getLogger( Relatorio.class );
public static int REPORT_PDF = 1;
public static int REPORT_EXCEL = 2;
public Relatorio()
{
}
private Connection getConnection() throws ClassNotFoundException, SQLException
{
String driver = "aaaaaaaaaaaa";
String url = "yyyyyyyyyyyyyyyyyyyyy";
String user = "user";
String pwd = "password";
Class.forName(driver);
Connection conn = DriverManager.getConnection( url, user, pwd );
return conn;
}
private void geraRelatorioPDF( JasperPrint filled, String caminho ) throws Exception
{
JasperExportManager.exportReportToPdfFile( filled, caminho );
}
private void geraRelatorioExcel( JasperPrint filled, String caminho ) throws FileNotFoundException, JRException, IOException
{
OutputStream output = new FileOutputStream(new File(caminho));
ByteArrayOutputStream xlsReport = new ByteArrayOutputStream();
byte bytes[] = new byte[10];
// exportação para excel
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, filled);
exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, xlsReport);
exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_FILE, caminho);
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);
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();
}
}