Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting a CSV File that contains HTML for Import to Excel

Tags:

export

csv

excel

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?

like image 879
Dave Avatar asked Jun 15 '10 21:06

Dave


1 Answers

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

like image 163
Mike Avatar answered Nov 13 '22 21:11

Mike