function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MayankAdmMayankAdm 

creating csv file through visualforce page

Hi All,

 

I am creating csv file through apex class and vf page all things working fine only it creating first Row blank

it means data wirte from 2nd row instead of first row

 

 

Thanks,

Mayank  

PrabhaPrabha

some code would be helpful to solve ur issue

MayankAdmMayankAdm

Hi Prabha,

 

What kind of code you are talking 

 

Thanks,

Mayank

MayankAdmMayankAdm

Hi,

 

 

This is my VF code 

 

<apex:page controller="exportOpportunityToExcelController" contentType="text/csv#testIRAS.csv" >


<apex:repeat value="{!lstWrapOpportunityReln}" var="item">


{!item.rowColumn1},{!item.rowColumn2},{!item.rowColumn3},{!item.rowColumn4}, {!item.rowColumn5},{!item.rowColumn6},{!item.rowColumn7},{!item.rowColumn8},{!item.rowColumn9}, {!item.rowColumn10},{!item.rowColumn11} ,{!item.rowColumn12},{!item.rowColumn13},{!item.rowColumn14},

 

</apex:repeat>
</apex:page>

 

Thanks,

Mayank

Rahul SharmaRahul Sharma
Try building a html table with headers first then use contentType as csv, With that you will be getting the headers too.

There might be the issue with formatting for the table.
sfdcfoxsfdcfox

The first row may be blank because of the extra line between <apex:page> and <apex:repeat>. Try removing that blank line.

 

Instead, you may want to format the string entirely in apex code, and render the page like this:

 

<apex:page controller="..." contentType="text/csv">
{!csv}
</apex:page>

Blank lines are emitted when they are present in the Visualforce code. Most of the time, this won't matter, since HTML ignores blank lines (mostly, anyways).

joshbirkjoshbirk

Definitely remove the blank line.  New lines in CSV will be seen as a row.

 

Also, I note there aren't headers defined.

MayankAdmMayankAdm

Hi sfdcfox,

 

Firstly thanks for your reply .I have removed the blank spaces

Now in this way i am implementing

 

<apex:page controller="exportOpportunityToExcelController" contentType="text/csv#testIRAS.csv" >
<apex:repeat value="{!lstWrapOpportunityReln}" var="item">
{!item.rowColumn1},{!item.rowColumn2},{!item.rowColumn3},{!item.rowColumn4},{!item.rowColumn5},{!item.rowColumn6},{!item.rowColumn7},{!item.rowColumn8},{!item.rowColumn9}, {!item.rowColumn10},{!item.rowColumn11} ,{!item.rowColumn12},{!item.rowColumn13},{!item.rowColumn14}</apex:repeat>
</apex:page>

 

but still same result I am getting and as per the our requirement we don't need header

 

Thanks,

Mayank

 

yashagarwalyashagarwal

Any luck with this one? I am also facing the same problem.

yashagarwalyashagarwal

Just after I posted this one I changed my code from  ;

 

<apex:page standardController="Account" extensions="accountController" contentType="text/csv#Aconts.csv" cache="true">
{!csvString}
</apex:page>

 

TO

 

<apex:page standardController="Account" extensions="accountController" contentType="text/csv#Aconts.csv" cache="true">{!csvString}</apex:page>


and the lines disappeared. Please mark this as solution if ti works for you as well.

MayankAdmMayankAdm

Hi Yash,

 

Its giving same error blank row still not gone

 

Thanks,

Mayank

SDFC_kittySDFC_kitty

Hello :)

 

I wonder if you kindly check this code for me. i wonder why it dose not work ?? i cant find any error in it, but when i test, the result is not like what i want. 

*listOfItems : store the key of mapFieldLabel

Any help, pls :(

 

Best,

---------------------------

<apex:page standardController="Object__c" showHeader="true" sidebar="false" extensions="theControllerr"
id="Thepage" contentType="text/csv#Export.csv;charset=utf8" cache="true" title="Downlaoding" readOnly="true">

<apex:repeat value="{!listOfItems}" var="a" id="theFieldsLoop">
"{!mapFieldLabel[a]}",
</apex:repeat>
</apex:page>

--------------------------------