You need to sign in to do that
Don't have an account?
Visualforce Messaging Attachment as Excel XLS
I am building an automated email which I am adding a Visualforce attachment that I would like to open as an XLS file in excel. I am doing so using the following messaging:attachment syntax.
<messaging:attachment renderAs="application/vnd.ms-excel" filename="testexcel.xls"> <c:TestExcel /> </messaging:attachment>
The component I am using I kept as simple as possible just to get it working, which is a 3 column table with 10 rows of contacts. Here is my component code.
<apex:component controller="TestClass" access="global"> <apex:dataTable value="{!Contacts}" var="c"> <apex:column value="{!c.Name}"/> <apex:column value="{!c.Email}"/> <apex:column value="{!c.Phone}"/> </apex:dataTable> </apex:component>
The message sends and the attachment shows up fine on the email. The issue I am having is while opening the file I get the "The file you are trying to open, 'testexcel.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?" message because it is not encoded correctly. Clicking open, opens the file just fine, but I would really like to find a way to prevent this warning message from popping up when my users open the file. I originally considered doing it in CSV, but I need to format certain cells with certain styling.
Does anyone know of any tags or headers I can try adding so that this warning message does not pop up, or does anyone have any idea how to force a formatted Visualforce table to open in Excel without warning? Thanks!
You will have to output the results in an XML format that Excel will recognize.
Something like this:
This is how salesforce.com itself gets around the message without outputting real Office binary code. Go ahead and give it a try.
Strangely enough, copying that exact code, pasting it into notepad and saving it as .xls - you still get the corrupt file message. There must be something added to excel files that is not visible when opening through notepad.
Hi,
I am also getting the same error message while opening the excel.
Did u get the solution?
Thanks.
No solution, Microsoft must have some hidden attribute appended to the file type that recognizes it as native excel.
Any Resolution on this?
I tried below but no success
1. showheader=false
2. no form tag on VF page
3. use style=”vnd.ms-excel.numberformat:@”
4. Use Meta tag :
Page is simple : just data table on account. Also if I open excel file in notepad i see junk script.
thanks
Try below.