Jump to content
Changes to the Jaspersoft community edition download ×

CSV: Force quoting on some text fields


Recommended Posts

By: Paul Stanton - wanto

CSV: Force quoting on some text fields

2006-06-12 18:39

Hi,

 

I have a report which has a text field value of "098123". When it gets to csv it is exported as "...,098123,..." which is correct, but when i open this with excel the value is displayed as "98123" which is incorrect.

 

the only solution i can think of is to force quoting of this field when it gets to csv so that it exports ...,"098123",... intead.

 

is there a way to force quoting of some or all csv fields?

 

 

By: stone_cold - bssai

RE: CSV: Force quoting on some text fields

2006-06-13 05:56

Hi Paul,

 

Better why dont u use the same csv file and create an EXCEL file using JasperExportManager.exporttoXls() that gives u and excel file too.

 

I mean basically using a csv data source and map them to get a report.

 

sesha

 

 

By: Paul Stanton - wanto

RE: CSV: Force quoting on some text fields

2006-06-14 16:26

unfortunately excel (xls) is not an option.

 

and if it were, i would just export the report to xls not re-export the csv to xls.

 

 

By: Paul Stanton - wanto

RE: CSV: Force quoting on some text fields

2006-06-21 17:38

i have found out that it is impossible to get excel to display a csv file properly with leading zero's.

 

the only way to achieve this is to replace '00','00' with ='00',='00' and this is not technically csv.

 

therefore i am moving to using excel as the recommended export format as well as supporting csv output for non-excel users.

 

 

By: Lucian Chirita - lucianc

RE: CSV: Force quoting on some text fields

2006-06-15 00:14

There is currently no parameter to force quotes on CSV export, you could add a feature request for this.

 

In the meantime, you can extend JRCsvExporter and force the quotes in the extended exporter by overriding the prepareText method like this:

 

protected String prepareText(String source)

{

String text = super.prepareText(source);

if (text != null && (text.length() == 0 || text.charAt(0) != '"'))

{

text = '"' + text + '"';

}

return text;

}

 

HTH,

Lucian

 

 

By: ACSD - acdourado

RE: CSV: Force quoting on some text fields

2006-06-22 02:51

Hi,

 

And there is a way to force that the quotes not appear in any fields, even the numeric ones? Or I have to extend JRCsvExporter class too?

 

Thanks,

Ana

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...