• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mahesh Rana
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
Kripal Singh
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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() );

}
}
 
Mahesh Rana
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kripal.
I appreciate your help.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18226
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Ramsden
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked it out.
Excel has got different formats for
DOS, MAC and Windows.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18226
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic