In a web application, I am generating a spreadsheet XML using an XSL template created from Excel 2010. I want this spreadsheet XML to open in Excel by default. So, I add the below properties to the response
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "Attachment;Filename=export.xls");
Response.Charset = "";
This opens the file in Excel, but because of the extension hardening feature of Excel 2010, displays the prompt -
The file you are trying to open, 'export[1].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?
If I click on yes, it opens up fine. But, is there a way the prompt can be completely skipped? I have read about the registry changes to disable the prompt in a user's machine. But, this is a public website and that solution will not work.
I can set the attachment filename to export.xml. If I save it and open in Excel, there is no prompt. But the XML will not open in Excel by default.
Any ideas, to open the spreadsheet xml in Excel, without the prompt?
Type Default programs in the search bar on Windows 10. Associate a file type or protocol with a program under Choose the program that Windows use by default in the Default Program Window. Select the . xml file type in the Associate a file type or protocol with a program Window and click on Ok.
The XML file you're trying to open doesn't refer to an XML schema. To work with the XML data that's in the file, Excel needs a schema based on the contents of the XML file. If that schema is incorrect or insufficient, remove it from your workbook.
This blog helped me workaround my problem.
https://ralph.blog.imixs.com/2013/02/16/how-to-generate-a-excel-sheet-with-xslt/
The trick is to add this processing instruction in your XSL template in the way mentioned in the above post.
<xsl:processing-instruction name="mso-application">
<xsl:text>progid="Excel.Sheet"</xsl:text>
</xsl:processing-instruction>
By doing this, you can specify the file extension as .xml, but it will open in Excel by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With