Skip to main content
Inspiring
January 17, 2008
Question

1st row blank on CSV...

  • January 17, 2008
  • 5 replies
  • 497 views
I'm curious why this is occuring. When I'm using the following code:

<cfsavecontent variable="myCVS">
Name,Address,Address2,City,State,Zip
<cfoutput
query="AllUsersCVS">#Cust_Name#,#Cust_Address#,#Cust_Address2#,#Cust_City#,#Cust_State#,#Cust_Zip##chr(10)#</cfoutput>
</cfsavecontent>

the 1st row in the CSV file is blank. How can I get it so it will have the
'Name, Address, Address2', etc on the 1st row, instead of the 2nd?


    This topic has been closed for replies.

    5 replies

    Inspiring
    January 17, 2008
    Steve Grosz wrote:
    > Ok, after changing the code to:
    >
    >
    > <cfsavecontent variable="myCVS">Name,Address,Address2,City,State,Zip
    > <cfoutput
    > query="AllUsersCVS">#Cust_Name#,#Cust_Address#,#Cust_Address2#,#Cust_City#,#Cust_State#,#Cust_Zip##chr(10)#</cfoutput></cfsavecontent>
    >
    > The 1st blank line is gone, but now there appears to be a blank record at
    > the end......
    >
    > Is it becuase of the chr(10) after the last record? If so, how can I get a
    > new record on each row without having a blank space at the end of the
    > recordset?
    >

    Another way to look at this is to put the line feed character at the
    beginning of the line. This would require you to remove the line feed
    currently hard coded between the ...,Zip and the <cfoutput...> lines.

    <cfsavecontent
    variable="myCVS">Name,Address,Address2,City,State,Zip<cfoutput
    query="AllUsersCVS"> <!--- NOTE HARD CODED LINE FEED HERE --->
    #Cust_Name#,#Cust_Address#,#Cust_Address2#,#Cust_City#,#Cust_State#,#Cust_Zip#</cfoutput></cfsavecontent>

    A trick that you may want to know that can possible help with
    readability of your code. You can hide hard coded line feed characters
    with CFML comment tags.

    <cfsavecontent variable="myCVS">...,Zip<!--- HIDDEN LIVE FEED CHARACTER
    ---><cfoutput query="AllUsersCVS"><!--- HIDDEN LINE FEED CHARACTER
    --->#chr(10)#...,#Cust_Zip#</cfoutput></cfsavecontent>
    Inspiring
    January 17, 2008
    Steve Grosz wrote:
    > Ok, after changing the code to:
    >
    > <cfsavecontent variable="myCVS">Name,Address,Address2,City,State,Zip
    > <cfoutput
    > query="AllUsersCVS">#Cust_Name#,#Cust_Address#,#Cust_Address2#,#Cust_City#,#Cust_State#,#Cust_Zip##chr(10)#</cfoutput></cfsavecontent>
    >
    > The 1st blank line is gone, but now there appears to be a blank record at
    > the end......
    >
    > Is it becuase of the chr(10) after the last record? If so, how can I get a
    > new record on each row without having a blank space at the end of the
    > recordset?
    >

    Yes, you have a line feed [chr(10)] character at the end of every line.
    This includes the last line so there will be an empty blank line at
    the end of the output. This may not actually be important, but if it is.

    You can either conditionally determine if that last linefeed character
    is output or you can write out your file one line a time using the
    <cffile action="append"...> tag to automatically handle this at the cost
    of much more file writing.

    To conditionally write out the line feed character:

    <cfoutput query="AllUsersCFS">...#iif(AllUsersCFS.currentRow NEQ
    AllUsersCFS.recordCount,DE(chr(10)),DE(''))#</cfoutput>

    Untested and untried, may take a bit of a tweak on the DE(chr(10)) function.

    OR

    <cfoutput query="AllUsersCFS">...<cfif AllUsersCFS.currentRow NEQ
    AllUsersCFS.recordCount>#chr(10)#</cfif></cfoutput>
    Inspiring
    January 17, 2008
    Ok, after changing the code to:


    <cfsavecontent variable="myCVS">Name,Address,Address2,City,State,Zip
    <cfoutput
    query="AllUsersCVS">#Cust_Name#,#Cust_Address#,#Cust_Address2#,#Cust_City#,#Cust_State#,#Cust_Zip##chr(10)#</cfoutput></cfsavecontent>

    The 1st blank line is gone, but now there appears to be a blank record at
    the end......

    Is it becuase of the chr(10) after the last record? If so, how can I get a
    new record on each row without having a blank space at the end of the
    recordset?

    "Ian Skinner" <iskinner@cdpr.ca.gov> wrote in message
    news:fmo9nb$525$1@forums.macromedia.com...
    > Steve Grosz wrote:
    >> I'm curious why this is occuring. When I'm using the following code:
    >>
    >> <cfsavecontent variable="myCVS">
    >> Name,Address,Address2,City,State,Zip
    >> <cfoutput
    >> query="AllUsersCVS">#Cust_Name#,#Cust_Address#,#Cust_Address2#,#Cust_City#,#Cust_State#,#Cust_Zip##chr(10)#</cfoutput>
    >> </cfsavecontent>
    >>
    >> the 1st row in the CSV file is blank. How can I get it so it will have
    >> the 'Name, Address, Address2', etc on the 1st row, instead of the 2nd?
    >
    > <cfsavecontent variable="myCVS"> <!--- REMOVE THIS RETURN CHARACTER --->
    > Name,Address,Address2,City,State,Zip
    > <cfoutput
    > query="AllUsersCVS">#Cust_Name#,#Cust_Address#,#Cust_Address2#,#Cust_City#,#Cust_State#,#Cust_Zip##chr(10)#</cfoutput>
    > </cfsavecontent>
    >
    > Unlike HTML output all the whitespace characters in a CSV output count. So
    > the Return you have at the end of the <cfsavecontent...> line before the
    > Name... line is recorded in your output. Remove it here and it will not
    > be in the file.
    >
    > <cfsavecontent variable="myCVS">Name,Address,Address2,City,State,Zip
    >


    Inspiring
    January 17, 2008
    Thanks! I will try that.....

    "Ian Skinner" <iskinner@cdpr.ca.gov> wrote in message
    news:fmo9nb$525$1@forums.macromedia.com...
    > Steve Grosz wrote:
    >> I'm curious why this is occuring. When I'm using the following code:
    >>
    >> <cfsavecontent variable="myCVS">
    >> Name,Address,Address2,City,State,Zip
    >> <cfoutput
    >> query="AllUsersCVS">#Cust_Name#,#Cust_Address#,#Cust_Address2#,#Cust_City#,#Cust_State#,#Cust_Zip##chr(10)#</cfoutput>
    >> </cfsavecontent>
    >>
    >> the 1st row in the CSV file is blank. How can I get it so it will have
    >> the 'Name, Address, Address2', etc on the 1st row, instead of the 2nd?
    >
    > <cfsavecontent variable="myCVS"> <!--- REMOVE THIS RETURN CHARACTER --->
    > Name,Address,Address2,City,State,Zip
    > <cfoutput
    > query="AllUsersCVS">#Cust_Name#,#Cust_Address#,#Cust_Address2#,#Cust_City#,#Cust_State#,#Cust_Zip##chr(10)#</cfoutput>
    > </cfsavecontent>
    >
    > Unlike HTML output all the whitespace characters in a CSV output count. So
    > the Return you have at the end of the <cfsavecontent...> line before the
    > Name... line is recorded in your output. Remove it here and it will not
    > be in the file.
    >
    > <cfsavecontent variable="myCVS">Name,Address,Address2,City,State,Zip
    >


    Inspiring
    January 17, 2008
    Steve Grosz wrote:
    > I'm curious why this is occuring. When I'm using the following code:
    >
    > <cfsavecontent variable="myCVS">
    > Name,Address,Address2,City,State,Zip
    > <cfoutput
    > query="AllUsersCVS">#Cust_Name#,#Cust_Address#,#Cust_Address2#,#Cust_City#,#Cust_State#,#Cust_Zip##chr(10)#</cfoutput>
    > </cfsavecontent>
    >
    > the 1st row in the CSV file is blank. How can I get it so it will have the
    > 'Name, Address, Address2', etc on the 1st row, instead of the 2nd?
    >
    >

    <cfsavecontent variable="myCVS"> <!--- REMOVE THIS RETURN CHARACTER --->
    Name,Address,Address2,City,State,Zip
    <cfoutput
    query="AllUsersCVS">#Cust_Name#,#Cust_Address#,#Cust_Address2#,#Cust_City#,#Cust_State#,#Cust_Zip##chr(10)#</cfoutput>
    </cfsavecontent>

    Unlike HTML output all the whitespace characters in a CSV output count.
    So the Return you have at the end of the <cfsavecontent...> line
    before the Name... line is recorded in your output. Remove it here and
    it will not be in the file.

    <cfsavecontent variable="myCVS">Name,Address,Address2,City,State,Zip