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?
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.
精彩评论