You need to sign in to do that
Don't have an account?
sundhar.mks1.3962649227519546E12
How to preview the excel file in visualforce page?
Hi,
how to view the excel file preview in visualforce page,Is this possible? kindly give any example or code
Thanks.
how to view the excel file preview in visualforce page,Is this possible? kindly give any example or code
Thanks.
https://success.salesforce.com/answers?id=90630000000gsbVAAQ
If instead you want to show a preview of an excel file (in an Attachmetn / Document of your ORG?) I think you should use some sort of JS libraries (e.g . http://www.hnwatcher.com/r/953659/Excel-file-preview-in-JavaScript or https://github.com/SheetJS/js-xlsx or http://flexpaper.devaldi.com/ ).
--
May the Force.com be with you!
I tried iframe but it's only download,i want to preview the excel document, how it is possible?
======================
<apex:page >
<apex:iframe src="https://c.na1.content.force.com/servlet/servlet.FileDownload?file=01530000001iage" scrolling="true" id="theIframe"/>
</apex:page>
I have Exported the Excel data but can not display the full view i got a Blobvalue error. When i add the condent type to apex page it only download excel file but not view the page
Actualy EXcel file Attached to "notes & attachment" in my org.how to view the file?
Thanks.
So you have to make a visual preview using Javascript or some other tool.
Try this http://oss.sheetjs.com/ tool JS based. You have to pass the content of the Attachment to the page (you can use Remoteactions or simply a getter but you have to use Base64 encoding otherwise you will encounter a Blobvalue error).
This is more tricky than it appears on first sight.
Hope this helps.
I have used this script with apex page. get the attachment body,Contenttype to SOQl query and bind the body to {!csvString}" but i did not get the solution
=========================
<script>
window.location.href = "data:application/pdf;base64,{!csvString}";
</script>
Thanks.
Try this previous forum discussion for more details (with excel file download): https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AY1q
This sould help you!
Kindly see my code, I have tried some way what our want to change my code
============================
Page
============================
<apex:page controller="UploadReportValue" contentType="application/vnd.ms-excel">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<!-- <apex:repeat var="attachment" value="{!attachedFiles.Body}"></apex:repeat>
<apex:iframe src="/servlet/servlet.FileDownload—file={!attachedFiles.Body}"/> -->
<apex:outputPanel >{!csvString}</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<!-- <script>
window.location.href = "data:application/pdf;base64,{!csvString}";
</script> -->
</apex:page>
=========================
Controller
=========================
Public Class UploadReportValue {
public String getCsvString() {
return null;
}
public Blob csvBlob{get; set;}
public Attachment attachedFiles{get;set;}
public String xlsHeader {
get {
String strHeader = '';
strHeader += '<?xml version="1.0"?>';
strHeader += '<?mso-application progid="Excel.Sheet"?>';
return strHeader;
}
}
public UploadReportValue() {
attachedFiles = [select Id,body,ContentType from Attachment where parentId =:'a0Zf000000567BR' Limit 1];
csvBlob = attachedFiles.Body;
String csvString = csvBlob.toString();
System.debug('============='+csvString);
}
}
Thanks.
Sundhar M
In the controller change:
with this:
Doing this makes the page attribute [contentType="application/vnd.ms-excel"] useless, so remote it.
I have changed but page is empty, no one dispaly on vf page
======================
page
======================
<apex:page controller="UploadReportValue" contentType="application/vnd.ms-excel">
<apex:form >
<script>
window.location.href = "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;content-disposition:attachment;base64, {!csvString}";
</script>
</apex:form>
</apex:page>
===================
Controller
===================
Public Class UploadReportValue {
public String getCsvString() {
return null;
}
public Blob csvBlob{get; set;}
public Attachment attachedFiles{get;set;}
public String xlsHeader {
get {
String strHeader = '';
strHeader += '<?xml version="1.0"?>';
strHeader += '<?mso-application progid="Excel.Sheet"?>';
return strHeader;
}
}
public UploadReportValue() {
attachedFiles = [select Id,body,ContentType from Attachment where parentId =:'a0Zf000000567BR' Limit 1];
csvBlob = attachedFiles.Body;
String csvString = EncodingUtil.base64Encode(csvBlob);
System.debug('============='+csvString);
}
}
Thanks.
Sorry i did not get exactly,Removed the contentType seee the below
==========================
<apex:page controller="UploadReportValue">
<apex:form >
<!-- <apex:pageBlock >
<apex:pageBlockSection >
<apex:repeat var="attachment" value="{!attachedFiles.Body}"></apex:repeat>
<apex:iframe src="/servlet/servlet.FileDownload—file={!attachedFiles.Body}"/>
<apex:outputPanel >{!csvString}</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
-->
<script>
window.location.href = "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;content-disposition:attachment;base64,{!csvString}";
</script>
</apex:form>
</apex:page>
be sure that the Controller constructor is querying an Attachment that is effectively on the ORG (I'm talking about the [select Id,body,ContentType from Attachment where parentId =:'a0Zf000000567BR' Limit 1]; query )
Can you please change my code,
============================
page
============================
<apex:page controller="UploadReportValue" ContentType="base64,{!csvString}">
<apex:form >
<script>
window.location.href = "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;content-disposition:attachment;base64,{!csvString}";
</script>
</apex:form>
</apex:page>
=========================
Controller
=========================
Public Class UploadReportValue {
public String getCsvString() {
return null;
}
public Blob csvBlob{get; set;}
public Attachment attachedFiles{get;set;}
public String xlsHeader {
get {
String strHeader = '';
strHeader += '<?xml version="1.0"?>';
strHeader += '<?mso-application progid="Excel.Sheet"?>';
return strHeader;
}
}
public UploadReportValue() {
attachedFiles = [select Id,body,ContentType from Attachment where parentId =:'a0Zf000000567BR' Limit 1];
csvBlob = attachedFiles.Body;
String csvString = EncodingUtil.base64Encode(csvBlob);
System.debug('============='+csvString);
}
}
Thanks.
In the given code only downloaded the attachment. But does not disaply the vf page, how to display the Attachment to vf page without downdloading?i want to view the full data to vf page
Thanks.
I thought you didn't want anymore to preview the attachment (the code you provided did exactly this, except that it was badly written).
If you want a preview you have to do some research and probably use some Javascript library.
For some hints read my first question, I've never developer this so I can't show here some code.
Anyway I believe that "http://www.hnwatcher.com/r/953659/Excel-file-preview-in-JavaScript" could do what you want to do.
Hope this helps
Thanks for this post. this helps me alot.
but, i have the problem with IE.the same code is working in Mozilla but not in IE..
can you please help me out.
Thanks in advance.
-- Suma.
I have single Excel sheet but this single excel sheet having multiple sheets(means multiple objects each sheet).How to import multiple sheets(means multiple objects with single excel with different sheets).
Using below code i was done import for single excel sheet for single object with but how to do import multiple objects(means i have one excel but this excel having multiple sheets(means multiple objects))
Thanks