+ Start a Discussion
Marcelo AgostinhoMarcelo Agostinho 

Problems converting VIsualForce Page to Excel

Hello! 

 

Well, i tried some examples of how to convert VF to Excel, and i did it with sucess.

 

But now when i convert my own VF Page to Excel, apparently it works fine, but when i try to open, the excel give the following message

"Cant read the file", 

 

Here is the code...

 

 

<apex:page controller="CarteiraCliente" sidebar="false" contentType="application/vnd.ms-excel">

<apex:pageBlock>
    <apex:form>
        <apex:commandButton value="Carrega Tabela" action="{!teste}"/>
    </apex:form>
</apex:pageBlock>

<apex:pageBlock title="Carteira de Cliente">
    <apex:pageBlockTable value="{!valoresClienteMes}" var="cliente" title="Carteira de Cliente">
    
        <apex:column id="nomeCliente" value="{!cliente.nomeCliente}"/>
        <apex:column id="valorTreze"  value="{!cliente.valorTreze}"/>
         
    </apex:pageBlockTable>
</apex:pageBlock>
    
   
    

</apex:page>

 

Tks!!!

 

uptime_andrewuptime_andrew

What happens if you take out the form?  Perhaps there's elements to that that aren't supported when converting to an Excel file?

 

Marcelo AgostinhoMarcelo Agostinho

Andrew, how are you doing?

 

Well, i tried to get out the form, and when i save the page, i get an excel file and when i try to open it, i got the same message.

 

Tks

uptime_andrewuptime_andrew

Hmm, I'm not sure.  If you remove the content type header (i.e. display as a visualforce page) are there any characters ther that may cause problems for Excel?

 

Can you create the example here and open with Excel: http://blog.sforce.com/sforce/2008/12/visualforce-to-excel.html

 

I'd try with those two things to start, and work backwords - simplify your page, and add stuff back in until you find the part that's causing the break. 

Marcelo AgostinhoMarcelo Agostinho

Andrew this is the exact link that i used to do the example.

 

Well tks for the hint! I ll do it, be back soon with the answer! I Hope.

Marcelo AgostinhoMarcelo Agostinho

Andrew, it is my fault, the problem is the commandButton, i removed it and it worked...

 

Now i have another, question, 

This button will call a method who ill populate the table...

 

How can i convert to XLS only an block of code?

Chiru GogulakondaChiru Gogulakonda

After Converting Visualforce page to excel.My visualforce page looka as blank page. It doesnot work any method, and action.please any  one help me out for this. I need to go another page. below mentioned my code.

 VF Page:

<apex:page standardController="Opportunity" contentType="application/vnd.ms-Office#CustomerSetupForm.xls" recordSetVar="opportunities" extensions="HipiAttachmentsExtens" >

<apex:pageBlock > <!--title="Opportunities"-->
<apex:pageBlockTable value="{!opportunities1}" var="Opty" border="1">

<apex:column value="{!Opty.PO_number__c}"/>
<apex:column value="{!Opty.Billing_Company_Name__c}"/>
<apex:column value="{!Opty.Company_city__c}"/>
<apex:column value="{!Opty.Company_State_country__c}"/>
<apex:column value="{!Opty.Billing_Address__c}"/>
<apex:column value="{!Opty.City__c}"/>
<apex:column value="{!Opty.State_Country__c}"/>
<apex:column value="{!Opty.Billing_Contact_Name__c}"/>
<apex:column value="{!Opty.Billing_Email_Address__c}"/>
<apex:column value="{!Opty.Billing_Contact_Phone__c}"/>
<apex:column value="{!Opty.Accounts_Payable_Contact_Name__c}"/>
<apex:column headerValue="Test"/>
<apex:column value="{!Opty.Accounts_Payable_Email_Address__c}"/>
<apex:column value="{!Opty.Account_Payable_Phone__c}"/>
<apex:column value="{!Opty.Contract_Administrator_Name__c}"/>
<apex:column value="{!Opty.Contract_Admin_Email_Address__c}"/>
<apex:column value="{!Opty.Contract_Admin_Phone__c}"/>
<apex:column value="{!Opty.Royalty_Reports_be_required__c}"/>
<apex:column value="{!Opty.Name_of_Person_Preparing_Report__c}"/>
<apex:column value="{!Opty.Email__c}"/>
<apex:column value="{!Opty.Phone__c}"/>
<!-- <apex:column value="{!Opty.Request_Contract_Number__c}"/> -->
</apex:pageBlockTable>

</apex:pageblock>

<!-- <apex:form >
<apex:pageBlock >
<apex:commandButton value="Go to previous page" onclick="MyFun();return false;"/>
</apex:pageBlock>
</apex:form>

<script language="JavaScript" type="text/javascript">

function MyFun(){
window.setInterval("window.top.close()",250);

}
</script> -->

</apex:page>

 

Controller:

 

public with sharing class HipiAttachmentsExtens {

public Static Boolean flag{set;get;}
public Opportunity Opp {get;set;}

public HipiAttachmentsExtens(ApexPages.StandardSetController controller) {

}

//public Opportunity Opp {get;set;}

public HipiAttachmentsExtens(ApexPages.StandardController controller) {

Opp = new Opportunity();

}

Public List<Opportunity> getopportunities1(){

ID Oppid = ApexPages.currentPage().getParameters().get('Oppid');

List<Opportunity> opps=[select PO_number__c,Billing_Company_Name__c,City__c,State_Country__c,Billing_Contact_Name__c,Billing_Email_Address__c,Billing_Contact_Phone__c,
Accounts_Payable_Contact_Name__c,Accounts_Payable_Email_Address__c,Account_Payable_Phone__c,Contract_Administrator_Name__c,Contract_Admin_Email_Address__c,Contract_Admin_Phone__c,
Royalty_Reports_be_required__c,Name_of_Person_Preparing_Report__c,Email__c,Billing_Address__c,Phone__c,Request_Contract_Number__c,Company_State_country__c,Company_city__c from Opportunity where id = : Oppid ];

return opps;

}



//This is used for saving ContractChecklist
public PageReference Saveforlater(){

return null;
}
//This is used for saving ContractChecklist
public PageReference Submit(){


return null;
}
public PageReference LoadOpp(){

// flag=true;
// return new PageReference('/'+Opp.id);

PageReference pr= new PageReference('/apex/HipiattachmentsPage?Oppid='+ApexPages.currentPage().getParameters().get('Oppid'));
return pr;
// return null;
}
}