如何自动打开导出的Excel文件 [英] How to automatically Open Exported Excel File
本文介绍了如何自动打开导出的Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有这个代码,导出字符串我传递给excel
So I have this code that Export string I pass to excel
Response.Clear()
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment;filename=MyExcelData.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.ms-excel"
Response.Output.Write(myDataString)
Response.Flush()
Response.End()
此代码要求我打开或保存文件。我的问题是有没有办法自动打开文件而不要求我打开或保存文件???
This code ask me to open or save the file. My question is is there a way that automatically open the file without asking me to either open or save the file???
推荐答案
不,因为这是一个安全风险。
No, as this is a security risk.
您可以尝试将Reponse.Header更改为以下内容:
You can try to change the Reponse.Header to the following:
Response.AddHeader("Content-Disposition", "inline;filename=" + fileName);
请记住,这是一种安全风险,不同浏览器的行为会有所不同。
Keep in mind this is a security risk and different browser will behave differently.
这篇关于如何自动打开导出的Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文