PDA

View Full Version : How to export the data in a pipedelimited format in csv file


sumanta
12-21-2009, 07:00 PM
Dear All,
I am able to export the data in a csv file.
But each value i am getting different column.

29 Pistler Richard A PLM-5000 RICHARD.PISTLER@SIEMENS.COM

As per my requirement how to export the row data in a column with pipedelimited format in csv file .
For Example::
384998|Ladd|Brian|A|700|Healthcare Diagnostics|a.b@stest.com
010503|Pora|Esther|A|SHI|tttt Instruments|c.d@test.com

Below given is the code
File csvFile = new File(Constants.getProperty("DATASTORE_GENERATED_FILE")
+ "/"
+ fileName);

out = new PrintWriter(new BufferedWriter(new FileWriter(csvFile)));



while(rs.next())

{
//------------Row Details Start here------------------
//String pernr = "'"+rs.getString("PER_NR")+"'";
String pernr = rs.getString("PER_NR");
String lname = rs.getString("LNAME");
String fname = rs.getString("FNAME");
String status = rs.getString("Status of Employee");
String socmapping = rs.getString("SOC_MAPPING");
String email = rs.getString("email");

String csvLine =
pernr+
","
+ lname
+ ","
+ fname
+ ","
+ status
+ ","
+ socmapping
+ ","
+ ","
+ email;

out.println(csvLine);

}

Please suggest me for the needful.

Thanks in advance.
Regards,
Sumanta Panda

sashank.narain
12-27-2009, 02:45 PM
I may be wrong but if u want it in CSV, why not straightway set the content type for the response?

response.setContentType("application/octet-stream");
response.setHeader("Content-disposition","attachment; filename=test.csv");