Skip to main content
Inspiring
May 23, 2007
Question

Excel export - getting rid of line breaks

  • May 23, 2007
  • 6 replies
  • 1873 views
I'm exporting data to an Excel Spreadsheet but when the Excel spreadsheet is generated, if the user has used a carriage return during data entry, it creates a a new row in Excel.

I've tried using a replace in the export field
#replace(Comments,Chr(13),"", "all")#

and if I use:
#replace(Comments,Chr(13),"xx", "all")#
I can actually see the xx, but the extra row is still being created before the rest of the entry starts.

Any ideas on getting rid of the line breaks during export?

Full Code is below (edited for clarity).

<CFSET tab=chr(9)>
<CFSET carriage=chr(13)>
<cfif action IS "export">
<CFHEADER name="Content-Disposition" value="inline; filename=MNC_Data.xls">
<cfcontent type="application/vnd.ms-excel">
<cfquery name="get_Data" datasource="#appDSN#">
SELECT ml.DateSubmitted, ml.FirstName,
ml.LastName, ml.Address1,
ml.Address2, ml.City, ml.State, ml.comments,
FROM #diff#mailing ml
</cfquery>

<cfoutput>Location#tab#Date Submitted#
FirstName#tab#
LastName#tab#
Address1#tab#
Address2#tab#
City#tab#
State#tab#
Postal#tab#
Comments#carriage#</cfoutput>

<cfoutput query="get_Data">
#LSDateFormat(DateSubmitted,'MM/DD/YYYY')##tab##TimeFormat(timestamp,'hh:mm:ss tt') ##tab#
#FirstName##tab#
#LastName##tab#
#Address1##tab#
#Address2##tab#
#City##tab#
#State##tab#
#Postal##tab#
#replace(get_Data.Comments,Chr(13),"", "all")#
#carriage#</cfoutput>
    This topic has been closed for replies.

    6 replies

    August 28, 2007
    Thats perfect! I did not know you could use pipes to separate, nor did I know you could use the actual characters you want to replace instead of the asci chr() tag.

    It worked great. Thanks.
    Inspiring
    August 28, 2007
    Is it possible you're misunderstanding replace()?
    chrome88Author
    Inspiring
    August 28, 2007
    I have it working with MX7, but I have found that when I put in more than two characters to replace it seemed to stop working.
    Inspiring
    August 28, 2007
    That would only replace occurrences of all three characters in that order. If you want to replace any] of those three characters, try a reReplace

    You must escape "." with a \ because it has a special meaning in regular expressions
    reReplace(showname, "[ |-|\.]","","ALL")
    chrome88Author
    Inspiring
    May 23, 2007
    I believe you're correct, because if I do a replace Chr(10) with "x" I can see the x being output.

    However, I'm not sure how to replace multiple characters,

    I tried putting:

    <cfset Comments = "#replace(get_data.Comments,Chr(10),"", "all")#">

    before the output, but it does not affect the output.

    thx,
    Inspiring
    May 24, 2007
    You can concatenate multiple characters with an "&"

    ...
    #replace(get_Data.Comments,Chr(13)&Chr(10),"", "all")#
    chrome88Author
    Inspiring
    May 25, 2007
    Thanks so much. That was the last piece of the puzzle for this project.
    Inspiring
    May 23, 2007
    It might also contain a Chr(10). Try replacing: Chr(13) & Chr(10)