CSV Output

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

Hi,

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.
Teodor
2001 JI Open Discussion's picture
Joined: Aug 10 2006 - 3:26am
Last seen: 17 years 1 month ago

6 Answers:

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.
drumsetdrummer's picture
Joined: Oct 20 2006 - 6:30am
Last seen: 16 years 11 months ago
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...
wegnerk's picture
1197
Joined: Aug 28 2006 - 10:31pm
Last seen: 17 years 1 month ago
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
Code:
http://jasperforge.org/sf/wiki/do/viewPage/projects.jasperreports/wiki/FAQ9</td></tr></tbody></table><br />
for a detailed explanation of how the report layout is calculated.<br />
<br />
HTH,<br />
Robin
rsilver@ns.sympatico.ca's picture
Joined: Aug 4 2006 - 3:46am
Last seen: 17 years 2 months ago
How it's calculated in jasper the csv layout?
I've to put a lot of filed and these are too long to stay on the page in a "single spaced vertical line"
how can I solve this problem?:blink:
thx
martina
6sic6's picture
143
Joined: Nov 26 2006 - 8:01pm
Last seen: 16 years 10 months ago
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).
snowbug's picture
65
Joined: Sep 22 2006 - 1:34am
Last seen: 17 years 1 week ago
Hi,

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,
Teodor
teodord's picture
53504
Joined: Jun 30 2006 - 9:00am
Last seen: 21 hours 43 min ago
Feedback