473,385 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 5877
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bryan Russell | last post by:
Hi, My asp/sql server application gets an error, but only when you use the Excel export option: <% Response.ContentType="application/vnd.ms-excel" %> (very popular w/ users) I think...
0
by: Simon | last post by:
Dear reader, By export a query to Excel the memo-field is cutoff to 255 characters in Excel. I do not know how I can export the total content of the memo field, more
4
by: Anthony Cuttitta Jr. | last post by:
I'm working on some procedures where Access queries are exported to Excel, and then later on, those same workbooks are openned, and I need to target a specific original sheet. Sometimes there will...
1
by: JMCN | last post by:
hello does anyone know why is there a character limitation (255) in excel when i export from the reports object in excel access? if i created a macro using the transferspreadsheet action from...
3
by: nologin | last post by:
Is it possible to export data exposed by DataView to Excel file for example ? Seba
8
by: Taffman | last post by:
I've searched this goup for an answer to this, there are many discussions that come close but non that I can find that actually addresses this particular problem. I'm exporting queries to Excel....
1
by: musicloverlch | last post by:
I need to export a query to Excel with a memo field. The memo field keeps getting cut off at 255 characters. If I just cut and paste, I get the whole memo field. I need it in Excel without...
2
by: Nefaria | last post by:
I'm constantly required to export data from Access to Excel for formatting and find it extremely difficult to remove the Chr(10) and Chr(13) codes from the imported data. A search and replace in...
7
Merlin1857
by: Merlin1857 | last post by:
Its great producing data for users to look at in your web pages and generally that is sufficient for their needs but sometimes you may want to supply your user with the data in a form they can...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.