Olá pessoal,
seguinte, estou fazendo uma apliação que precisa gerar um relatório.
Estou utilizando uma lista de objetos que passo como parâmetro para o relatório, ao invés de buscar no banco, por teste. O problema está quando tento exportar para o Excel é lançada uma exceção java.lang.IllegalArgumentException
O erro é o seguinte:
java.lang.IllegalArgumentException: Sheet name cannot be blank, greater than 31 chars, or contain any of /\*?[]
Acredito que 'sheet' seja a aba do Excel.
Já tentei setar o valor via parâmetro da seguinte forma:
exporter.setParameter( JRXlsExporterParameter.SHEET_NAMES, new String [] {"Teste"} );
sem sucesso. Está aqui abaixo o código do método que gera o relatório. Estou utilizando Struts e Hibernate (que não vem ao caso). A versão do iReport que utilizei para fazer o relatório é a mais recente : 1.2.6 e os jars dele eu coloquei na lib do meu projeto. Qualquer ideia, por favor, meu prazo já passou fazem três dias, hehehe. Obrigado.
private void carregaRelatorioIndicadoresExcel( HttpServletRequest request, HttpServletResponse response, List indicadores ) throws Exception {
ServletOutputStream ouputStream = response.getOutputStream();
try {
Map parameters = new HashMap();
String reportFilePathRelative = "/src/br/com/cfn/gvp/relatorio/jasper/IndicadoresDasResidencias_Anderson.jasper";
HttpServletRequest context = request;
String reportFilePath = context.getRealPath(reportFilePathRelative);
File reportFile = new File(reportFilePath);
byte[] bytes2 = null;
JRXlsExporter exporter = new JRXlsExporter();
// Abre aconexao com o sevidor
FileInputStream input = new FileInputStream(reportFile);
JasperPrint jasperPrint = null;
// pegaBean() gera uma lista qualuqer com objetos para o relatorio
List l = pegaBean();
JRBeanCollectionDataSource beanSource = new JRBeanCollectionDataSource(
l);
jasperPrint = JasperFillManager.fillReport(reportFilePath,
parameters, beanSource);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
exporter.setParameter( JRExporterParameter.JASPER_PRINT, jasperPrint );
exporter.setParameter( JRExporterParameter.OUTPUT_STREAM, baos );
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
exporter.setParameter( JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE );
exporter.setParameter( JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE );
exporter.exportReport();
bytes2 = baos.toByteArray();
} catch (JRException e) {
String er = e.getMessage();
}
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition","attachment; filename=file1.xls");
response.setContentLength(bytes2.length);
ouputStream.write(bytes2, 0, bytes2.length);
ouputStream.flush();
ouputStream.close();
} catch (Exception e) {
String a = e.getMessage();
throw new ServletException(e);
}
}