Multiline CSV export to Excel produces unrecognized characters?

felciano felciano at gmail.com
Mon Mar 24 02:30:11 EDT 2008


Hi --

Is there a standard way to use the csv module to export data that
contains multi-line values to Excel? I can get it mostly working, but
Excel seems to have difficulty displaying the generated multi-line
cells.

The following reproduces the problem in python 2.5:

import csv
row = [1,"hello","this is\na multiline\ntext field"]
writer = csv.writer(open("test.tsv", "w"), dialect="excel-tab",
quotechar='"')
writer.writerow(row)

When opening the resulting test.tsv file, I do indeed see a cell with
a multi-line value, but there is a small boxed question mark at the
end of each of the lines, as if Excel didn't recognize the linebreak.

Any idea why these are there or how to get rid of them?

Ramon



More information about the Python-list mailing list