| 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: 14491
|
|
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: 27
|
|
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: 14491
|
|
"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.
|
 |
 |
|
|
subject: What is CSV format ? Urgent......
|
|
|