默认情况下将文件类型保存为xls [英] save file type as xls by default

查看:101
本文介绍了默认情况下将文件类型保存为xls的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我使用以下代码将html表转换为excel并且工作正常但默认保存文件类型是Web Page(*。htm; * .html )我希望它是xls我该怎么办



Hi
I have used the following code to convert the html table to excel and it works fine but the default save file type is Web Page(*.htm; *.html) and I want it to be xls what should I do

HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=Test.xls")
HttpContext.Current.Response.Write(strHTML)
HttpContext.Current.Response.End()

推荐答案

HttpContext.Current.Response.ContentType = "application/x-download";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(fileInfo.Name));
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.WriteFile(fileInfo.FullName);
HttpContext.Current.Response.End();


这篇关于默认情况下将文件类型保存为xls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆