MVC4:导出.xlsx文件使用Chrome通过MVC脱颖而出。它适用于.xls的而不是原来的.xlsx [英] MVC4: Export an .xlsx file to excel through mvc using chrome. It works for .xls but not .xlsx

查看:304
本文介绍了MVC4:导出.xlsx文件使用Chrome通过MVC脱颖而出。它适用于.xls的而不是原来的.xlsx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能导出.xlsx文件使用Chrome通过MVC脱颖而出。它适用于.xls的而不是原来的.xlsx

How can I export an .xlsx file to excel through mvc using chrome. It works for .xls but not .xlsx

Response.ClearContent();
    Response.AddHeader("content-disposition", "attachment; filename= Estimate1.xlsx");
    Response.ContentType = "application/excel";
    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);

    Response.Write(sw.ToString());
    Response.End();

当我打开Excel文件。它表明这个样子。 Excel无法打开文件'FileName.xlsx',因为文件格式或文件扩展名是无效的。

and when i open excel file. it show like this. "Excel cannot open file 'FileName.xlsx' because the file format or file extension is not valid."

这么多AP preciated您的帮助! :)

so much appreciated your help! :)

推荐答案

试着改变内容类型的.xlsx

Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

这篇关于MVC4:导出.xlsx文件使用Chrome通过MVC脱颖而出。它适用于.xls的而不是原来的.xlsx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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