Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding carriage return for Excel

Status
Not open for further replies.

pixiesfb

Programmer
Apr 27, 2001
62
US
I'm creating an excel file with .csv extension and items are appearing in a horozontal row. How can I add CRs list vertically?


<cfset itemcnt=1>
<cfloop query=&quot;xlist&quot;>
<cfif itemcnt is 1>
<cfset txtout='&quot;#agreenum#&quot;'>
<cfset itemcnt=2>
<cfelse>
<cfset txtout=txtout&',&quot;#agreenum#&quot;'>
</cfif>
</cfloop>

<cffile action=&quot;Write&quot; file=&quot;#outfile#&quot; output=&quot;#txtout#&quot;>
 
Hi pixiesfb

CSV files can contain normal carriage returns which are Chr(13) & Chr(10), well that's on windows machines . Unix it is Just chr(10). But for CSV the 13,10 combo should work just fine. It will increment the row.
I would do this:

<cffile action=&quot;Write&quot; file=&quot;#outfile#&quot; output=&quot;#txtout#&chr(13)&Chr(10)&quot;>

I think that works. I haven't tested it but if not then Add the Chr's in earlier.

Have fun...

 
Mmmm, getting close. I tried

<cffile action=&quot;Write&quot; file=&quot;#outfile#&quot; output=&quot;#txtout#&chr(13)&Chr(10)&quot;>

didn't work,
Then tried

<cffile action=&quot;Write&quot; file=&quot;#outfile#&quot; output=&quot;#txtout#&#chr(13)#&#Chr(10)#&quot;>

didn't work,
Then tried

<cfloop query=&quot;xlist&quot;>
<cfif itemcnt is 1>
<cfset txtout='&quot;#agreenum##chr(10)##chr(13)#&quot;'>
<cfset itemcnt=2>
<cfelse>
<cfset txtout=txtout&',&quot;#agreenum##chr(10)##chr(13)#&quot;'>
</cfif>
</cfloop>

Still no luck, any idea(s)?
 
Hmmm..

I actually set up a test and was surprised to find that I didn't need to add a carriage return between rows, Not sure why but when I do add a return it increments 2 rows. But anyway... here is the correct syntax for that, sorry I didn't test it first. I'm just now having a cup of coffee ;)

<cfset txtout=&quot;#agreenum#&quot;&chr(10)>

The point is that the &quot;&chr(10)&quot; needs to be outside the double quotes of your initial string data.

Have fun...
 
I got it to work with

<cfloop query=&quot;xlist&quot;>
<cfif itemcnt is 1>
<cfset txtout=&quot;#agreenum##chr(13)#&quot;>
<cfset itemcnt=2>
<cfelse>
<cfset txtout=txtout&&quot;#agreenum##chr(13)#&quot;>
</cfif>
</cfloop>

I tried your idea but did not work for me, thanks for getting me on the right track though!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top