Recent posts

Using the CSV emitter with BIRT 2.3.0

I’ve seen several questions lately on how to use the BIRT CSV Emitter example that is explained in the Integrating and Extending BIRT book. While the book goes into great detail explaining what each file does and even how to build the entire example yourself, my blog post will just give the basic steps necessary to use the example. The steps below assume you have an Eclipse IDE and have also downloaded the BIRT Runtime engine.

First we need to download the example CSV emitter project and the associated classes used to run the example.  You can find the files at this link. You will need both org.eclipse.birt.report.engine.emitter.csv.zip and ExecuteCSVReport.zip from the Report rendering section.
Next, we need to import the files into Eclipse.
Import BIRT Extension Project

  1. From the Eclipse IDE, select Import from the File menu and then select Existing Projects into Workspace under General and press Next.
  2. Select org.eclipse.birt.report.engine.emitter.csv.zip as the archive file and then make sure the project displayed is checked before pressing Finish.
  3. Repeat these steps to import the project from ExecuteCSVReport.zip. Don’t worry about any reference errors in the project at this time… we’ll correct those later.

Now that our projects are imported, we need to export the CSV emitter plug-in.

Export BIRT plugin

  1. Right-click on the org.eclipse.birt.report.engine.emitter.csv project and select Export.
  2. Choose Deployable plug-ins and fragments from the Plug-In Development choices and press Next.
  3. Make sure your plug-in is selected and then choose your ReportEngine directory that is part of your BIRT Runtime Engine download.

Now that our new plug-in is exported, we need to test it.  The ExecuteCSVReport project contains an example report and code we can use for this test but first we need to fix the project references to point to our own BIRT Runtime Engine files.

  1. Right-click the ExecuteCSVReport project and select Properties.
  2. Select Java Build Path and then Libraries
  3. Highlight all the JAR files that indicate they are missing and press the Remove button.
  4. Press the Add External JARs button and select all the files from your ReportEngine/lib directory.
  5. Press the Add External JARs button again and this time select the new plug in you just created.  If you accepted the defaults from the export step above, then this should be in the ReportEngine/plugins directory in a file called org.eclipse.birt.report.engine.emitter.csv_1.0.0.jar.

Now that our project references are corrected, we need to correct one more reference in our ExecuteReport.java file that points to the BIRT Runtime Engine.

  1. Double-click ExecuteReport.java to open this file in the editor.
  2. Change the setEngineHome line to point to your ReportEngine directory like the example shows below.

config.setEngineHome( “C:/work/eclipse/BIRT_230/birt-runtime-2_3_0/ReportEngine” )

Once the ExecuteReport.java file is saved we can run the example.

  1. Right click on ExecuteReport.java and select Run As | Java Application. You will see a message that says “We are done!!!” in the Console if everything worked correctly.
  2. Press F5 on your ExecuteCSVReport project to refresh the files and you should now see a new file called csvReport.csv in the reports folder.

BIRT CSV Output

7 Comments
Comment by peterfopma:

Hi Virgil,

I played around quite a bit with the CSV-Emitter. After a few changes it works nicely.

One thing puzzles me - maybe you can point out the cause of this behaviour.
I added the CSV-Emitter to the plugin-directory. Restarted Eclipse and now I can add conditions for the visibility of report elements depending on the choosen format.
In the design-file the condition is added for the format “csv” - but in practice it only work when this is changed to “CSV” (uppercase).
I converted all strings to lowercase “csv” but still it only works for uppercase - any idea why this is so?

Thanks
Peter Fopma

Comment by peterfopma:

OK - I figured it out, just after I posted the message.
In case anyone stumbles across the same problem:

The format option for the engine is case insensitve at first sight. You can pass “CSV” and “csv” and in both cases the CSV-Emitter is used.
But… when using the conditional visibility for an object the format is stored in the report template in lower case and this is compared - case sensitive - to the format option set for the engine.

For everything to work correctly you must make sure that the desired format ist set to “csv” (lowercase) in the render options.

By the way, I tested this in Version 2.2.1. It might be different in later versions.

Peter Fopma

Comment by vdodson:

Peter, I’m glad you got this working and thanks for updating the page for everyone else.

Virgil

Comment by ERospide:

Was this CSV emitter issue resolved in the latest release of the BIRT engine?

Eddy Rospide

Comment by kanneganti:

Hi Virgil,
Using BIRT 2.5.1.
getting the following error at run time
Nov 20, 2009 4:24:55 PM org.eclipse.birt.report.engine.api.impl.RunAndRenderTask doRun
SEVERE: Error happened while running the report.
java.lang.Error: Unresolved compilation problems:
The method assert(boolean) is undefined for the type CSVWriter
The method assert(boolean) is undefined for the type CSVWriter

at org.eclipse.birt.report.engine.emitter.csv.CSVWriter.open(CSVWriter.java:80)
at org.eclipse.birt.report.engine.emitter.csv.CSVReportEmitter.start(CSVReportEmitter.java:236)
at org.eclipse.birt.report.engine.emitter.CompositeContentEmitter.start(CompositeContentEmitter.java:225)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:169)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:75)
at ExecuteReport.executeReport(ExecuteReport.java:64)
at ExecuteReport.main(ExecuteReport.java:81)
org.eclipse.birt.report.engine.api.EngineException: Error happened while running the report
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:199)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:75)
at ExecuteReport.executeReport(ExecuteReport.java:64)
at ExecuteReport.main(ExecuteReport.java:81)
Caused by: java.lang.Error: Unresolved compilation problems:
The method assert(boolean) is undefined for the type CSVWriter
The method assert(boolean) is undefined for the type CSVWriter

at org.eclipse.birt.report.engine.emitter.csv.CSVWriter.open(CSVWriter.java:80)
at org.eclipse.birt.report.engine.emitter.csv.CSVReportEmitter.start(CSVReportEmitter.java:236)
at org.eclipse.birt.report.engine.emitter.CompositeContentEmitter.start(CompositeContentEmitter.java:225)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:169)
… 3 more

Comment by kanneganti:

Resolved the issue. was using jdk 1.4
upgraded to 1.6

Comment by morphes:

Hi Virgil,

we are using the BIRT Viewer to generate custom reports. One customer asked for the CSV export, which I successfully implemented in JDK 1.5.

The problem I now have is that the CSV Export seems like it uses pagination and therefore outputs the header every 40 lines. I have seen a parameter in the report itself (showHeaderOnFirst) which doesn’t fit. I tried to use a custom master page with a height of somewhere above MountEverest but also that doesn’t work.

Within the CSV Emitter code I tried the parameter outputMasterPageContent and turned that to false. But even that does not solve the problem.

So my question is: What can I do to get the CSV Emitter to work like eg the XLS Emitter that only outputs the header once and then prints all the data? No paging required..

Thanks for your help in advance!
Regards
Clemens

Leave a comment

Sorry, you must log in to post a comment.


vdodson
vdodson
Virgil Dodson is a Developer Evangelist at Actuate Corporation. Virgil has over 13 years experience as a software developer. For the past 6 years he has helped Java developers get started with Actuate's embedded reporting products. He holds a Bachelor of Science degree in Computer Information Systems from DeVry.
more...