Export Data To CSV
public class exportCSVController { public List> myList {get;set;} public exportCSVController() { myList = new List
>(); List
temp = new List (); for(Integer i = 0; i < 2500; i++){ if(temp.size() < 1000){ myClass m = new myClass(); m.val1 = 'val1 ' + i; m.val2 = 'val2 ' + i; temp.add(m); } else{ myList.add(temp); temp = new List (); myClass m = new myClass(); m.val1 = 'val1 ' + i; m.val2 = 'val2 ' + i; temp.add(m); } } myList.add(temp); } public class myClass{ public string val1 {get;set;} public string val2 {get;set;} } }
<apex:page controller="exportCSVController" cache="true" contentType="text/csv#Export.csv" language="en-US"> "Col A","Col B" <apex:repeat value="{!myList}" var="a"> <apex:repeat value="{!a}" var="asub"> "{!asub.val1}","{!asub.val2}" </apex:repeat> </apex:repeat> </apex:page>
Reference: http://boards.developerforce.com/t5/Apex-Code-Development/How-to-export-data-to-CSV-file-using-Apex/td-p/166567/page/2
Comments
Post a Comment
Feedback - positive or negative is welcome.