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
BJMBJM 

Upload Contacts From Excel File not a CSV File Through Visualforce Page

Hi All
          How to Upaload Contacts From Excel File not a CSV File Through Visualforce Page
     


Thanks in Advance...!
NagaNaga (Salesforce Developers) 
Hi Bjm,

- Almost all Salesforce objects can be retrieved in Excel format via the standard reporting interface
- The same report could be printed as a PDF using PDF-generating software on the client's PC
- If you cannot export data using the standard reporting interface, contact your Salesforce administrator

- There may be a requirement to generate lists of Salesforce data outside of the standard reporting interface
- This is possible using simple Visualforce code
- The Visualforce page can use the <apex:column> tag to repeat over SObject or custom wrapper class rows
- The <apex:page> tag should use showHeader="false" renderAs="pdf" orcontentType="application/vnd.ms-excel#SalesForceExport.xls", depending on whether you want a PDF or Excel file

- Below is some sample code that loops over Contact ID and Name fields
- This code is not considered production quality and should be subjected to your full development life-cycle, including UAT 


Resolution
=========================================================
To Download PDF VISUALFORCE Page
=========================================================

<apex:page controller="contactquery" showHeader="false" renderAs="pdf">
    <apex:pageBlock title="Export Results" >
        <apex:pageBlockTable value="{!cs}" var="contact">
            <apex:column value="{!contact.ID}"/>
            <apex:column value="{!contact.Name}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

=========================================================
Download Excel VISUALFORCE Page
=========================================================

<apex:page controller="contactquery" contentType="application/vnd.ms-excel#SalesForceExport.xls" cache="true">
    <apex:pageBlock title="Export Results" >
        <apex:pageBlockTable value="{!cs}" var="contact">
            <apex:column value="{!contact.ID}"/>
            <apex:column value="{!contact.Name}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

=========================================================
Query Controller (Query the data you need)
=========================================================

public class contactquery{
    public List<Contact> cs{get; set;}
    public contactquery()
    {
    cs = new List<Contact>();
       for (Contact c : [Select id, Name from Contact])
       {       
           cs.add(c);
       }
    }


Best Regards
Naga kiran
BJMBJM
Hi Naga kiran,
                     Thanks for you response, Here i need to Upload list of Contacts into Contact object.

I have an ecxel file the file has Contacts i need to upload these contacts of excel file into Contact Object using Visualforce Page.

Here if the file is CSV it is working fine but if the file is excel it showing the error how can i achieve this.


Thanks and Regards