How can I exclude unwanted line breaks from a .csv file?

I want to export data from my MySQL database into a .csv file and then import the .csv file into Excel.
One of the fields in my database is a comments field where the users have included line breaks.  When I currently export this into Excel using a .csv format I find that the comments field is split over many cells because of these linebreaks.

I have tried the REPLACE command on the query which calls up the data to be exported looking for CHR(10) & CHR(13)  and replacing them with CHR(34).  This results in an error message telling me that the database does not recognise the function CHR.

I have also tried replacing the linebreak with another character (a $), opening up the .csv file in Word, replacing the unwanted linebreaks in the comments field then replaceing my $ sign with a linebreak and then saving the .csv file and importing the new .csv into Excel.  This works but it is too clumsy to expect users to do this themselves.

What I need is either a method of removing the unwanted linebreaks before I export the file or else a method by which I can use Excel to import the .csv in the correct format.

Can anyone help?
NemetonaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

azadisaryevCommented:
how exactly are you creating your csv file?

if you query your db first, then output the query into a <cfsavecontent> to create you csv content and then write a csv file using cffile, use the REPLACE() function on the comments column in the cfoutput, not in the query sql.

and, on a Window$ server, the linebreak is chr(13)&chr(10), NOT the other way around.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
eszaqCommented:
If you have some free formatted text data in your MySQL database fields (and it seems that you do), I would import into .tsv format, not .csv (can be imported to Excel just as easily) . But first, I would clean up all the carriage returns and tabs and such - just replace them all with single white-space character. So, output for each row, that you add to your .tsv file would be:

<cfoutput query="yourQuery">
#db_column_1#      #REReplaceNoCase(db_column_text_type, "[[:space:]]", " ", "all")#      #db_column_3#
</cfoutput>

(spaces between db fields are tab characters)
0
ChizlCommented:
You can wrap the results in double quotes and it will not break them out like that.   So basicly the CSV will be quote comma delimited.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

eszaqCommented:
Chizl:
I thought of using double quotes
BUT if it is free-form text input from the users (some sort of editorial contents) -
where is guarantee that there are no quotes inside the fields? I just think that stripping off all the extra white spaces and using .tsv format is the least painful solution in terms of putting work into preventing possible errors.
0
azadisaryevCommented:
for TSV format, use #chr(9)# instead of putting actual literal tabs in the <cfsavecontent>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.