Activity Forums Salesforce® Discussions How can I create a new line in a Visualforce CSV without using Apex code?

  • How can I create a new line in a Visualforce CSV without using Apex code?

    Posted by Deepak on October 11, 2019 at 12:57 PM

    How can I create a new line in a Visualforce CSV without using Apex code?

    Laveena replied 6 years, 7 months ago 2 Members · 1 Reply
  • 1 Reply
  • Laveena

    Member
    October 11, 2019 at 1:04 PM

    Hi Deepak,

    With no other answers posted, I’m afraid this may be the best that you’re able to achieve.

    There doesn’t seem to be a clean way of doing this. I think the best way, is to use Apex, but, after experimenting there may be one extremely hacky way to achieve this. Based on your example of n at the beginning of the line forcing newLines, but also outputting the literal value, I tried a couple of things. First,   at the beginning will force a newline, but also include a space in the first column, I couldn’t find a way around this, so I just added a rowCount column, to force this newline.

    <apex:page readOnly=”true”
    contentType=”application/octet-stream#MyCsv.csv”
    sidebar=”false”
    standardStylesheets=”false”
    showHeader=”false”
    cache=”true”
    expires=”0″>


    <apex:variable value=”{!1}” var=”rowNum”/>
    <apex:outputText value=”Row,Column 1,Column 2,Column 3″/>
    {!rowNum},<apex:outputText value=”aVal1,aVal2,aVal3″/><apex:variable var=”rowNum” value=”{!rowNum+1}”/>
    {!rowNum},<apex:outputText value=”bVal1,bVal2,bVal3″/><apex:variable var=”rowNum” value=”{!rowNum+1}”/>
    {!rowNum},<apex:outputText value=”bVal1,bVal2,bVal3″/><apex:variable var=”rowNum” value=”{!rowNum+1}”/>
    {!rowNum},<apex:outputText value=”bVal1,bVal2,bVal3″/><apex:variable var=”rowNum” value=”{!rowNum+1}”/>
    {!rowNum},<apex:outputText value=”bVal1,bVal2,bVal3″/><apex:variable var=”rowNum” value=”{!rowNum+1}”/>
    </apex:page>

    Thanks

Log In to reply.