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
Sunny670Sunny670 

How to import data present in alist to excel file using apex coding

I have a batch class where in the execute method i will get a list of records. Now in final method i need to send a mail and attach the above list as an excel file. All the data in the list should be loaded into excel file. I tried but its not working. any sample code on how to convert a list data file into an excel sheet?

Abhi_TripathiAbhi_Tripathi

Hey sunny,

 

You can use this code sample , and for more information you can check out this blog

http://abhithetechknight.blogspot.in/2013/09/salesforcecom-custom-dataloader.html

 

 

Code Sample

 

public class processCSV {

           

            //Variables

             public blob BlobFile{get;set;}
             headersList = new list<string>();
             public string RecordsInTheFile {get;set;}

 

             //Method
             public void processingFile(){

             

                         //file processing
                        RecordsInTheFile = BlobFile.tostring();//taking blob file to a string

                        headersList = RecordsInTheFile.split('\r\n');//splitting at new line

                        System.debug('value of excel file :::::::::' + headersList);
           }
}

 

 

On page

<apex:inputFile value="{!BlobFile}" filename="{!RecordsInTheFile}" accept=".csv" />

<apex:commandButton action="{!processingFile}" value="Upload File" id="theButton" style="width:70px;" />