默认情况下将文件类型保存为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();