Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/05/2010, 08:01
west140
 
Fecha de Ingreso: mayo-2006
Mensajes: 101
Antigüedad: 18 años
Puntos: 2
Como hacer un reporte en swing??

Hola que tal, ojala alguien pueda ayudar, estoy tratando de hacer un reporte con ireports. Ya tengo el archivo .jasper pero no me funciona a la hora de invocar el evento por medio de un boton, alguna idea. Y otra, es que no me reconoce el JRPdfExporter???
Este es mi codigo:
Código HTML:
public void reporte(){
        String fileName = "C:\\report1.jasper";
        String outFileName = "C:\\report1.pdf";
        HashMap hm = new HashMap();
        try {
            // Fill the report using an empty data source
            JasperPrint print = JasperFillManager.fillReport(fileName, hm, new JREmptyDataSource());

            // Create a PDF exporter
            JRExporter exporter = new JRPdfExporter();

            // Configure the exporter (set output file name and print object)
            exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outFileName);
            exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);

            // Export the PDF file
            exporter.exportReport();

        } catch (JRException e) {
            e.printStackTrace();
            System.exit(1);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
tambien ten go este otro pero tampoco jala:
Código HTML:
 public void reporte(){
        try
        {
        //Ruta de Archivo Jasper
        String fileName="C:\\reports2.jasper";
        //Ruta de archivo pdf de destino
        String destFileNamePdf="C:\\reports2.pdf";
        //Ruta de archivo xls de destino
        String destFileNameXls="C:\\reports2.xls";

        //Pasamos parametros al reporte Jasper.
        Map parameters = new HashMap();
        parameters.put("sql_query", new String("select * from pacientes"));
        
        //Preparacion del reporte (en esta etapa se inserta el valor del query en el reporte).
        JasperPrint jasperPrint=JasperFillManager.fillReport(fileName,   parameters, getConnection());

        //Creación del PDF
        JasperExportManager.exportReportToPdfFile(jasperPr  int, destFileNamePdf);

        //Creación del XLS
        JRXlsExporter exporter = new JRXlsExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFileNameXls);
        exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
        exporter.exportReport();

        System.exit(0);
     }
     catch (Exception e)
     {
            System.out.println(e.getMessage());
     }
    }

Última edición por west140; 06/05/2010 a las 08:24