0

This visualforce page renders a csv but all the data is on one row. Where did I go wrong, how do I get a new row after every apex:repeat?

Note: The code below is on one line to prevent empty header rows when rendering.

<apex:page standardController="Custom_Object__c" cache="true" contentType="text/csv#filename.csv" language="en-US"> Col A","Col B","Col C","Col D","Col E",<apex:repeat value="{!Custom_Object__c.Custom_Object_Members__r}" var="co"> {!co.Custom_Object__c.Name},{!co.Contact__r.FirstName},{!co.Contact__r.LastName},{!co.Contact__r.Email},{!co.Contact__r.MobilePhone}, </apex:repeat> 

This code all goes on line:

<apex:page standardController="Custom_Object__c" cache="true" contentType="text/csv#filename.csv" language="en-US"> Col A","Col B","Col C","Col D","Col E",
<apex:repeat value="{!Custom_Object__c.Custom_Object_Members__r}" var="co"> {!co.Custom_Object__c.Name},{!co.Contact__r.FirstName},{!co.Contact__r.LastName},{!co.Contact__r.Email},{!co.Contact__r.MobilePhone}, 
</apex:repeat></apex:page>

This code puts line break where needed (it seems a new line with anything in it adds a new row, "_" in this example.)

<apex:page standardController="Custom_Object__c" cache="true" contentType="text/csv#filename.csv" language="en-US"> Col A","Col B","Col C","Col D","Col E",
_
<apex:repeat value="{!Custom_Object__c.Custom_Object_Members__r}" var="co"> {!co.Custom_Object__c.Name},{!co.Contact__r.FirstName},{!co.Contact__r.LastName},{!co.Contact__r.Email},{!co.Contact__r.MobilePhone}, 
_
</apex:repeat></apex:page>

This example also gives line breaks.

<apex:page standardController="Custom_Object__c" cache="true" contentType="text/csv#filename.csv" language="en-US"> Col A","Col B","Col C","Col D","Col E",
_<apex:repeat value="{!Custom_Object__c.Custom_Object_Members__r}" var="co"> {!co.Custom_Object__c.Name},{!co.Contact__r.FirstName},{!co.Contact__r.LastName},{!co.Contact__r.Email},{!co.Contact__r.MobilePhone}, 
_</apex:repeat></apex:page>

For whatever reason, I need to have text before a return, the visualforce tags themselves do not trigger a new line....what the waffle....

0

1 Answer 1

3

You need to add a few newlines:

<apex:page standardController="Custom_Object__c" cache="true" contentType="text/csv#filename.csv" language="en-US"> Col A","Col B","Col C","Col D","Col E",
<apex:repeat value="{!Custom_Object__c.Custom_Object_Members__r}" var="co"> {!co.Custom_Object__c.Name},{!co.Contact__r.FirstName},{!co.Contact__r.LastName},{!co.Contact__r.Email},{!co.Contact__r.MobilePhone}, 
</apex:repeat></apex:page>

apex:repeat tends to be pretty literal when it comes to things like that. Make sure you don't include any space between </apex:repeat> and </apex:page> if you don't want an extra blank newline at the end.

2
  • Thank you for your help, still no luck, keeps it on one line. Any thoughts? No matter how many lines I break the vf code on it still comes out as one line. Sep 11, 2017 at 19:37
  • If I add new lines before the Col A, Col B, etc. it does honor those, but not after. Seems Strange Sep 11, 2017 at 19:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .