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
SushupsiSushupsi 

AutoPopulating an Excel from the Detailed Page in salesforce.

Hi All,

 

Firstly thank you for all the support from the forums. It has been such a great help for developers.

 

My query for the day:

 

I wanted to auto populate few fields in the Excel sheet (spread sheet) from the details in the detailed page of a lead on click of a custom button.

 

I have tried the following approach :

 

<apex:page standardController="Account" contenttype="application/vnd.ms-excel#contacts.xls" cache="true">
<apex:form >
<apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false"/>
</apex:form>
</apex:page>

 Using the above approach i am able to create an excel that can accommodate only fixed format depending on the Detailed page design.

 

I would like to populate the fields in a pre-existing format of excel that is present on my desktop. Could any one direct me how could i feed or autopopulate the correct data in an existing proforma on a button click.

 

Do we use any webservices or a class, Please walk me through this.

Urgent help is needed.

 

TIA.

- Sushupsi.

Best Answer chosen by Admin (Salesforce Developers) 
SushupsiSushupsi

I have tried the auto population of excel in other format using the Attachment Object.

 

The code looks like the following :

My Method()
{
Attachment acc = new Attachment();
String attachBody = '\n\n'+','+','+','+','+','+','+','+','+','+','+'SF ID:'+'\n\n';
        attachBody += ','+','+','+','+','+'AGENT PRE-QUALIFICATION\n';
        attachBody += 'OWNER # 1 NAME:'+','+','+'Value,'+','+'OWNER #2 NAME:'+','+'Value\n';
        attachBody += 'HOME ADDRESS:'+','+','+'Value,'+','+'HOME ADDRESS:'+','+'Value\n';
        attachBody += 'CITY:'+','+','+'Value,'+','+'CITY:'+','+'Value\n';

acc.Body = Blob.valueOf(attachBody);
        insert acc;
}

 This actually helps. Hope if any one requires this it might help them.

NOTE: I have written it on button click.

 

-Sushupsi

 

All Answers

Shilpa_SFShilpa_SF

Hi,

 

   Salesforce only generates the fixed format depending on the Detailed page design. It cannot be populated with  fields in a pre-existing format of excel . Because salesforce only Renders it as Excel and it will not take care of the formatting of the Excel file.

SushupsiSushupsi

I have tried the auto population of excel in other format using the Attachment Object.

 

The code looks like the following :

My Method()
{
Attachment acc = new Attachment();
String attachBody = '\n\n'+','+','+','+','+','+','+','+','+','+','+'SF ID:'+'\n\n';
        attachBody += ','+','+','+','+','+'AGENT PRE-QUALIFICATION\n';
        attachBody += 'OWNER # 1 NAME:'+','+','+'Value,'+','+'OWNER #2 NAME:'+','+'Value\n';
        attachBody += 'HOME ADDRESS:'+','+','+'Value,'+','+'HOME ADDRESS:'+','+'Value\n';
        attachBody += 'CITY:'+','+','+'Value,'+','+'CITY:'+','+'Value\n';

acc.Body = Blob.valueOf(attachBody);
        insert acc;
}

 This actually helps. Hope if any one requires this it might help them.

NOTE: I have written it on button click.

 

-Sushupsi

 

This was selected as the best answer