470,631 Members | 1,648 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,631 developers. It's quick & easy.

Multiline CSV export to Excel produces unrecognized characters?

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
Mar 24 '08 #1
2 5734
On Sun, 23 Mar 2008 23:30:11 -0700, felciano wrote:
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?
Any chance you are doing this on Windows and Excel doesn't like the
return+linefeed line endings that Windows produces when writing files in
text mode? Try 'wb' as mode for the output file.

Ciao,
Marc 'BlackJack' Rintsch
Mar 24 '08 #2
>
Any chance you are doing this on Windows and Excel doesn't like the
return+linefeed line endings that Windows produces when writing files in
text mode? Try 'wb' as mode for the output file.

Ciao,
Marc 'BlackJack' Rintsch
Fixed! Can't believe I missed that...

Thank you for the quick reply!

Ramon
Mar 24 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Anthony Cuttitta Jr. | last post: by
3 posts views Thread by nologin | last post: by
1 post views Thread by musicloverlch | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.