File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes What is CSV  format ?     Urgent...... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "What is CSV  format ?     Urgent......" Watch "What is CSV  format ?     Urgent......" New topic
Author

What is CSV format ? Urgent......

Mahesh Rana
Ranch Hand

Joined: Sep 05, 2001
Posts: 139
Hi guys,
My boss wants me to write a servlet to generate output in
the CSV (is that the correct word ?) format.
Fortunately, my servlet is generating XML data.
I think, i will have to change the XSL only.
Can someone tell me the mime type
(and anything you know about it)?


SCJP2
Kripal Singh
Ranch Hand

Joined: Jul 26, 2001
Posts: 254
CSV is nothing but Comma Seperated file . You can open a blank MS Excel Sheet. Type some content and save as Comma Delimited(CSV) . Then you can open the csv file in notepad and see the format .
here is a sample servlet code to do it . You can change your XSL accordingly .
public class TestExcel extends HttpServlet {
/** Creates new TestExcel */
public TestExcel() {
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doPost(req, res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
PrintWriter out = res.getWriter();
StringBuffer result = new StringBuffer();
res.setContentType("application/vnd.ms-excel");
result.append("1\t2\t3\t4\t5\n");
result.append("A\tB\tC\tD\tE\n");
result.append("A\nB\nC\nD\nE\n");
out.println( result.toString() );

}
}


# Help an unprivileged kid.<br /> Whatever u do will make a difference...<br /> ...to a child's life & ur own #<br /><a href="http://www.cry.org/" target="_blank" rel="nofollow">www.cry.org/</a>
Mahesh Rana
Ranch Hand

Joined: Sep 05, 2001
Posts: 139
Thanks Kripal.
I appreciate your help.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960
    
  19

CSV stands for Comma-Separated Values, and is normally a set of values separated by commas broken into rows terminated by your favorite end-of-line characters. And yes, it's fairly easy to set up XSL to transform those XML tags into commas and end-of-line'
s.


Customer surveys are for companies who didn't pay proper attention to begin with.
Paul Ramsden
Greenhorn

Joined: Sep 22, 2000
Posts: 28
Just a note if you're thinking of offering the CSV output to users in the 'rest of the world' (non-US)
Here in Germany Excel seems to have other default separators than in the US. It appears to expect semi-colons and not commas. This may well be the case in other countries too.
At the time I could not find any concrete documentation on this issue at M$.
Paul
Mahesh Rana
Ranch Hand

Joined: Sep 05, 2001
Posts: 139
I checked it out.
Excel has got different formats for
DOS, MAC and Windows.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960
    
  19

"Here in Germany Excel seems to have other default separators than in the US. It appears to expect semi-colons and not commas. This may well be the case in other countries too."
Have you checked to see if "comma" separated CSVs are improperly displayed? The Excel delimited text import feature was designed for a number of different delimiters, including spaces, tabs, vertical-bars (an old Unix favorite), and, so far as I know, semicolons. When you open a delimited text as a file, it tries to guess and presents a dialog -- which it doesn't do when displaying in a browser, so I don't know if it limits itself to a particular delimiter set or not.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is CSV format ? Urgent......
 
Similar Threads
Problem in reading csv file
exporting to CSV
How to download different files in struits dppending on the file format
Binary Data in CSV Report
csv with jsp