• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)?
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kripal.
I appreciate your help.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I checked it out.
Excel has got different formats for
DOS, MAC and Windows.
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic