Tuesday, July 11, 2006

Writing CSV from Java

I recently tried to find a open source Java CSV writer released under a commercially friendly license. To my surprise I could not find one.

CSVs are still the easy solution when you want to export to any spreadsheet program. The only big problem is getting it right for Excel as Microsoft has its own opinion about CSV.

Anyway, since I did not find any, I wrote my own. It has the following features:
- streaming output (big files are no problem)
- uses Java5 printf formatting for flexible column formats
- settable separation character, locale and encoding
- verifies numer of columns

I also wrote a View implementation for use in a Spring MVC environment.

Here are some possible improvements:
- more automatic support for different Excel versions (dependent on locale)
- introduce a CsvWriterFactory to enable easier Spring wiring

I don't think my employer would minds if this went opensource. For example with an Apache license. Anybody interested?

Update 2007-10-23: I think our troubles are finally over: meet Super CSV!


  1. opencsv is an opensource CSV library with a commercial-friendly license http://opencsv.sf.net/

    It includes a writer interface. But not much help I suppose if you've already written your own :)

  2. Thanks!
    I dismissed that library immediately because the description says 'parser'.

  3. Note to self:

  4. Hi!

    I'm definitely interested! I'm working on the java to csv part of my internship and i'm on the brink of frustration because csvprinter and parser from Ostermiller's website aren't working. can you pelase help me out?


  5. Laurej, could you explain in which way they aren't working? I am not sure my simple writer will fit your needs.

    Unfortunately I do not have immediate access to that code. It's been a long time ago I wrote it.

  6. Just out of curiosity are there any features in your CSV implementation that would be worth carrying over into the Super CSV project?

    Your input is much appreciated.