tags:

views:

39

answers:

2

I would like to export a CSV file from my application for importing into Excel (or any other spreadsheet that supports CSV files). Anyhow, one of the cells in my table have rich content (i.e. HTML) which can, of course, contain commas as well as other HTML characters and formatting. I realize that Excel "can" handle HTML formatted text, but exporting it as CSV tends to screw up the data for importing. Is there some particular way I can format that particular cell so that imports correctly?

A: 

Provided you enclose all your fields in double-quotes (or some other delimeter, but double quotes are the most common), then commas in the field data should not present a problem.

You may, of course, encounter problems if your data also contains double quotes. If double quotes are present in the field value, these must be escaped by placing another double quote next to it.

The Wikipedia page on CSV files is worth reading, as it explains the problems, and the solutions, quite well:

http://en.wikipedia.org/wiki/Comma-separated_values

Mike
A: 

I decided against using CSV files for exporting data. Instead, I went with a different option; namely, using a HTML table. Excel recognizes the content as HTML when I export data as a table and preserves (for the most part) ALL of the formatting of the rich content in any of the cells.

Dave