在 Web 应用程序中,我正在使用 XSL 模板生成电子表格 XML。我希望这个电子表格 XML 默认在 Excel 中打开。因此,我将以下属性添加到响应中:
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "Attachment;Filename=export.xls");
Response.Charset = "";
但是,这有两个问题,首先我收到以下消息:
The file you are trying to open, 'Response.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?
第二,当我尝试保存它时,默认情况下它会尝试另存为 .xml 文件。我希望它默认保存为 Excel 文件,有人知道这样做的方法吗?