+ Start a Discussion
Amit Singh1989Amit Singh1989 

Display Excel data in visualforce page

Hi Friends,

 

here is my problem

"I want to display Excel data in visualforce page".

could any one please explain me that how to do this?

 

 

Thanks,

Amit Singh

Navatar_DbSupNavatar_DbSup

Hi,

     have you upload the excel sheet in documents?if yes then you can show the excel data at visual force page.

     to follow this sample code.

 

   

document d = [select id,name, ContentType from document where name="excel data"];
if(d[0].ContentType d[0].ContentType == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')
         {
            Contentdataid = d[0].id;
            strOrgId  = UserInfo.getOrganizationId(); 
            content = '/servlet/servlet.ImageServer?id=' + Contentdataid + '&oid='+ strOrgId ;
            PageReference pg = new PageReference(content);
            pg.setRedirect(true);
            return pg; 
             
         }

 

 Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Amit Singh1989Amit Singh1989

thank you,

but me requirement is something different....

i want an vf page where user will select any csv file then i want to give a button which will be used to convert that csv file into pdf report...

 

here is the code which i am using now.

 

<apex:page Controller="testReportExtension">
 <apex:form >

  <apex:inputFile value="{!contentFile}" filename="{!nameFile}" />

  <apex:commandButton action="{!ReadFile}" value="Read File" id="theButton"/>

 </apex:form>

</apex:page>




public class testReportExtension
{
public string nameFile{get;set;}
public Blob contentFile{get;set;}
public testReportExtension()
{

}

public Pagereference ReadFile()
{
nameFile=contentFile.toString();
System.Debug('***************************************'+nameFile);
return null;
}

 debug is showing result properly for namfile....

 

but i want to show the result in another vf page in pdf format (by using render as attribute).

I don't know that how to do this.

 

could you please any modification to do that?

 

Thank you

 

Navatar_DbSupNavatar_DbSup

one thing you can do create a visual force with renderAs ="pdf " and controller will be same.May be it can help you

 

public Pagereference ReadFile()
{
nameFile=contentFile.toString();
System.Debug('***************************************'+nameFile);
pagereference pr = new pagereference('/apex/demo');
pr.setredirect(true);
return pr;
}

<apex:page controller="testReportExtension" renderAs="pdf">
<apex:form>
<apex:outputtext value="{!nameFile}">
</apex:form>
</apex:page>

 

Amit Singh1989Amit Singh1989

 

Hi Navatar_DbSup,

 

I am trying as you have suggested in the last post.

 

But the new page does not display anything.

 

Thanks,

Amit S

 


Navatar_DbSupNavatar_DbSup

yes, you are right. one thing you can do with excel, you can save that excel in documents and retrive that excel in another page which is renderAs pdf from document object.Tryout this way maybe it help you.

Amit Singh1989Amit Singh1989

Could you please give me any full example.

 

Thanks

anshul9887anshul9887

I used your method but i am unable to show data in vf page.

vf page:-

 

<apex:page controller="excelpdfwork2" >
<apex:form >
<apex:commandButton action="{!fff}" value="showexcel"/>
</apex:form>
</apex:page>

 

 

controller:-

 

public with sharing class excelpdfwork2 {
/*public excelpdfwork2(){
fff();
}*/

public Pagereference fff(){
document d = [select id,name,type,ContentType from document where name='excel data'];
System.debug('@@@@@'+d);
System.debug('@@contenttype@@@'+d.ContentType);
System.debug('@@type@@@'+d.Type);
System.debug('*****outside if condition***');
PageReference pg;
//if(d.ContentType == 'application/vnd.ms-excel')
//{
System.debug('*****inside if condition***');
id Contentdataid = d.id;
Id strOrgId = UserInfo.getOrganizationId();
String content = '/servlet/servlet.ImageServer?id=' + Contentdataid + '&oid='+ strOrgId ;
System.debug('----url---->'+content);
pg = new PageReference(content);
pg.setRedirect(true);
//return pg;

//}
return pg;
}
}

SidharthSidharth
i am trying too but unable to render the csv file in vf page. i have stored the csv in documents.

vf page:
<apex:page controller="test_renderExcelFile" action="{!fff}">
</apex:page>

controller:
public class test_renderExcelFile{
    public Pagereference fff(){  
        document d = [select id,name, ContentType, Type from document where name='Field Description'];
        PageReference pg;
            id Contentdataid = d.id;
            id strOrgId  = UserInfo.getOrganizationId();
            string content = '/servlet/servlet.ImageServer?id=' + Contentdataid + '&oid='+ strOrgId ;
            pg = new PageReference(content);
            pg.setRedirect(true);
            return pg;             
    }
   
}
sundhar.mks1.3962649227519546E12sundhar.mks1.3962649227519546E12
Hi,
 i got xcel data attchment to get the query, How to display the xcel data to visualforce page?

==============================
Controller
==============================
Public Class UploadReportValue {

    String recId;
    
    public UploadReportValue(ApexPages.StandardController controller) {
       // recId = controller.getId();    
    }
    
    public String getFileId() {
        String fileId = '';
        List<Attachment> attachedFiles = [select Id,body,ContentType from Attachment where parentId =:'a0Zf000000567BR'];
        if( attachedFiles != null && attachedFiles.size() > 0 ) {
            fileId = attachedFiles[0].Id;
        }
        return fileId;    
    }
}

Thankyou...
Colton MathewsColton Mathews
Did anyone find a workable code for this? To be able to upload a file and have it show on the same page?