Hi,

For the BIRT part you need to install somewhere a BIRT runtime. Essentially,
this an equinox OSGi runtime with a folder structure like:

{root}-configuration`
         -plugins

If you have extended BIRT by adding your own ODA extensions then you have to
drop them on the plugins folder. There is also a folder (e.g.
plugins/org.eclipse.birt.report.data.oda.jdbc_2.3.0.v20080610/drivers) where
you have to drop any JDBC drivers you need to connect to your database (in
case you are using standard ODA drivers). I usually install the BIRT runtime
under WEB-INF...

The next step is to have instantiate this runtime and use it to generate
your reports. I do this via a class like the following:


public class Birt {
        
        .............

        private static IReportEngine engine;


        public static final void startEngine() {
                try {
                        if(engine != null)
                                return;
                        
                        EngineConfig engCnf = new EngineConfig();               
        
                
engCnf.setEngineHome(ConfigGlobal.i.resuelveRuta("WEB-INF/birt").toString());
                        
engCnf.setLogConfig(ConfigGlobal.i.resuelveRuta("../logs").toString(),
Level.ALL);                     
                        Platform.startup(engCnf);
                        IReportEngineFactory factory = (IReportEngineFactory) 
Platform
                                .createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
                        engine = factory.createReportEngine(engCnf);
                        engine.changeLogLevel( Level.OFF );                     
                        
                } catch (Throwable ex) {
                        log.fatal("", ex);
                }
        }
        
        public static final void stopEngine() {
                try {
                        engine.destroy();
                        engine = null;
                } catch (Exception e) {
                }
        }
        
        public static IReportEngine getEngine() {
                if(engine == null) {
                        startEngine();
                }
                return engine;
        }
 

        public static void generateBirtReport(String file, 
                        String fmt, 
                        OutputStream out, 
                        IdSql area, 
                        ReportInfo petA, 
                        JSONObject parametros_Reporte, Locale locale, boolean 
autoPageBreaking)
throws Exception {
                Attachment attachment = Attachment.loadFromTable(file, area);
                File tmpDir =
ConfigGlobal.i.resuelveRuta(LectorConfig.i.get().getChild("dirs").getChild("tmp").getValue());
                // creating a resource locator that is capable of retrieving 
libraries 
                // or images from the database...
                DataBaseResourceLocator dataBaseResourceLocator = new
DataBaseResourceLocator(area);
                IReportRunnable design =
getEngine().openReportDesign("test",attachment.getAsInputStream(),
dataBaseResourceLocator);
        
updateDataSources((ReportDesignHandle)design.getDesignHandle().getModuleHandle(),
petA);
                IRunAndRenderTask renderTask = 
getEngine().createRunAndRenderTask(design);
                RenderOption opcRend;
                if ("pdf".equals(fmt)) {
                        PDFRenderOption opc = new PDFRenderOption();
                        opc.setOutputFormat("pdf");
                        //ReportDesignHandle designHandle =
(ReportDesignHandle)design.getDesignHandle().getModuleHandle();                 
                        //designHandle.setDisplayName(null);
                        // para reducir la pagina tal como sale desde el 
diseƱador BIRT
                        opc.setOption(PDFRenderOption.PAGEBREAK_PAGINATION_ONLY,
autoPageBreaking);
                        opc.setOption(PDFRenderOption.FIT_TO_PAGE, 
autoPageBreaking);
                        
                        opcRend = opc;
                } else if ("excel".equals(fmt)){
                        // TODO: find if there is 
                        opcRend = new RenderOption();
                        opcRend.setOutputFormat("xls");                 
                } else {
                        HTMLRenderOption opc = new HTMLRenderOption();
                        opc.setHtmlTitle(design.getReportName());
                        opc.setBaseImageURL("/recursos/img/x.birt-img?imagen=");
                        opc.setImageDirectory(tmpDir.getAbsolutePath());
                        opc.setImageHandler(new HTMLServerImageHandler());
                        opcRend = opc;
                }
                // hanlde report paramteters.
                if(parametros_Reporte != null) {
                        Iterator<String> it = 
(Iterator<String>)parametros_Reporte.keys(); 
                        while(it.hasNext()) {
                                String param = it.next();
                                try {
                                        // first try to handle the parameter as 
multivalued.
                                        JSONArray array = 
parametros_Reporte.getJSONArray(param);
                                        Object[] values = new 
Object[]{array.length()};
                                        for(int i=0; i < array.length(); i++) {
                                                try {
                                                        values[i] = 
array.get(i);
                                                } catch (Exception e) {
                                                        values[i] = null;
                                                }
                                        }
                                        renderTask.setParameterValue(param, 
values);
                                } catch (Exception e) {
                                        // if parameter is not multi-valued 
then treat it as single-valued.
                                        String value = 
parametros_Reporte.getString(param);                             
                                        renderTask.setParameterValue(param, 
value);
                                }                               
                        }
                }
                opcRend.setOutputStream(out);                           
                renderTask.setLocale(locale);
                renderTask.setRenderOption(opcRend);
                renderTask.run();
        }
        .........

}

This class initializes a singleton BIRT runtime and the
generateBirtReport(...) method can be used to read the report design from a
database and generate the corresponding report (PDF, excel, HTML).  If you
filter out the logic that is specific to my use case you can easily build
your own machinery for building reports based on code given above.

As for the generation of the download link there should be plenty of
examples and/or related threads in this list... 

Best,

Ernesto







newbieabc wrote:
> 
> The generation of the excel report.
> I am really new to BIRT and wicket..
> I've created the BIRT report (report.rptdesign)(in eclipse) but need it to
> be output as xls.
> I'd really appreciate some help. 
> Thank you
> 
> 
> reiern70 wrote:
>> 
>> Sure you can... Which part is giving you problems? The generation of the
>> excel report with BIRT? Or the creation of the link?
>> 
>> Best,
>> 
>> Ernesto
>> 
>> newbieabc wrote:
>>> Hello..
>>> How can create a download link on a webpage, that converts a BIRT report
>>> to
>>> excel format and downloads to client machine?
>>>
>>> Thank you.
>>>   
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/DownloadLink%2C-BIRT-report-tp21218997p21238208.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to