Jump to content
Changes to the Jaspersoft community edition download ×

Recommended Posts

By: CosmoMaverick - cosmo-maverick

CSV Output

2002-09-30 13:40

I've added the CSV output from the patch list, but it's doing odd things. Instead of a standard csv file (first line the headers, the rest is more or less a data dump in csv format), I'm getting output that looks like it's trying to emulate the report layout.


Has anyone been able to work around this and if so could you point me in the right direction?


Is there a way to access pull the data directly before jasperreports lays it all out in a paginated format?


Thanks for any help.



By: Teodor Danciu - teodord

RE: CSV Output

2002-10-17 13:21




Why is it that you cannot write some code

that simply gets the data from your database

and puts it in a CSV file?


Why do you have to use JasperReports if its

way of laying out things is not what you expect?


In fact, what exactly do you expect from a CSV

file and why do you think you need a reporting tool

for the job?


I hope this helps.


Link to comment
Share on other sites

  • 2 months later...
  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

I'm having the same issue and thought I'd answer for CosmoMaverick since he/she never replied:


>In fact, what exactly do you expect from a CSV

>file and why do you think you need a reporting tool

>for the job?


By definition a CSV stands for Comma Separated Values and is a data-only format. It is often used to load data into databases, etc. One would only expect there to be a header row, followed by the corresponding data rows.


On Windows, if one has Excel installed, Excel will by default open a CSV file, but CSV is *NOT* a Microsoft format, it’s a universal data format. Hence, the frustration that the header/footer and page breaks display.


>Why is it that you cannot write some code

>that simply gets the data from your database

>and puts it in a CSV file?


>Why do you have to use JasperReports if its

>way of laying out things is not what you expect?


Our application has 79 different reports. On screen, we give users the choice of PDF, Excel or Data Only (CSV). If we have to write separate code to handle 79 different CSV files, that becomes a development and maintenance nightmare. It’s much easier to use the same code block with logic that handles which type of JRExporter is used than to re-create everything that’s been previously set up in all the .jrxml files.


All this being said, is there anyway to get the JRCsvExporter to stop printing the page headers/footers/breaks? I'm using Jasper 1.2.5.

Link to comment
Share on other sites

Hi, I also had that problem, and i solved it with the "printWhenExpression" of the pageHeader and Title. For the rest of my report, i already had a parameter "fileformat" and depending on this parameter, the title and pageheader are printed or not.


would be a nice thing, to have a JRCsvEporterParameter which switches off the pageheader/title...

Link to comment
Share on other sites

When dealing with CSV file output, remember that the jasper algorithm for deciding the format of the output is quite strict. You want to make sure to align your fields on the same vertical space and try not to have too many levels(vertical levels that is) of data.


Review the FAQ at


for a detailed explanation of how the report layout is calculated.




Link to comment
Share on other sites

  • 2 months later...
  • 4 weeks later...

I also think the export as CSV logic is flawed. As drumsetdrummer has already laid out, the JasperReport CSV export does not conform to the common expectation, if it is not a standard. - Why does anyone wanted to use a csv file that does not give you consistent column orders? If it is useless, why do create it in the first place?


Just to make it more interesting, when I export a report in csv format, I noticed the same column is placed after the 4th comma, and sometimes it is not, depending on which page it is. Apparently, it is due to the page grid calculation.


Also, the above mentioned solution of using the printWhenExpression may not be optimal as it depends on the parameters, which is used when generating the JasperPrint object. In other words, once the JasperPrint object is generated, whether an element is visible is already determined and can't be changed, no matter which format you decide to use.


Ideally, same JasperPrint object would serve for multiple displays (screen, xls, csv, etc). In order to achieve this, I think JasperReport should allow setting arbitrary data on any given element through the similar fashion as how you set the printWhenExpression. In this case, for example, you can then attach a boolean value to an arbitrary key for the element you'd like to see when output to csv format, and the exporter will select only those elements (current JRGridLayout defines a couple of element selectors internally).

Link to comment
Share on other sites



We are always happy to receive contributions to the project.

If you have or think you could come up with a better CSV exporter, please contribute it back to the community.


But first, please make sure you are not using JasperReports just to generate CSV files. It would be too much overhead to use an intensively graphic engine like JasperReports to produce simple flat text files.

A simple "for" loop statement in a JSP file would always do better than any sophisticated algorithm trying to extract pure data from the pixel-perfect, free-layout documents that JasperReports generates.


JasperReports was created with printing in mind and for years I was reluctant to introduce a CSV exporter as it did not make much sense. People should use simpler and more straightforward tools for generating CSV.


Thank you,


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...