MVC导出Excel .xlsx提示文件格式或文件扩展名无效
不知道要导出.xlsx需要什么格式?请各位指正...谢谢大家!
public void ExportToExcel()
{
System.IO.StringWriter sw = new System.IO.StringWriter();
string str="<?xml version=\"1.0\"?><?mso-application progid=\"Excel.Sheet\"?><Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:html=\"http://www.w3.org/TR/REC-html40\"><DocumentProperties xmlns=\"urn:schemas-microsoft-com:office:office\"><Author>User</Author><LastAuthor>User</LastAuthor><Created>2012-10-10T11:18:43Z</Created> <Company>微软中国</Company><Version>11.5606</Version></DocumentProperties><ExcelWorkbook xmlns=\"urn:schemas-microsoft-com:office:excel\"><WindowHeight>9225</WindowHeight><WindowWidth>18180</WindowWidth><WindowTopX>240</WindowTopX> <WindowTopY>120</WindowTopY><ProtectStructure>False</ProtectStructure><ProtectWindows>False</ProtectWindows></ExcelWorkbook><Styles><Style ss:ID=\"Default\" ss:Name=\"Normal\"><Alignment ss:Vertical=\"Center\"/> <Borders/><Font ss:FontName=\"宋体\" x:CharSet=\"134\" ss:Size=\"12\"/> <Interior/> <NumberFormat/> <Protection/> </Style></Styles><Worksheet ss:Name=\"Sheet1\"><Table ss:ExpandedColumnCount=\"1\" ss:ExpandedRowCount=\"1\" x:FullColumns=\"1\" x:FullRows=\"1\" ss:DefaultColumnWidth=\"54\" ss:DefaultRowHeight=\"14.25\"> <Row> <Cell><Data ss:Type=\"String\">fdfd</Data></Cell> </Row> </Table><WorksheetOptions xmlns=\"urn:schemas-microsoft-com:office:excel\"><Selected/><ProtectObjects>False</ProtectObjects><ProtectScenarios>False</ProtectScenarios></WorksheetOptions></Worksheet></Workbook>";
//string str = ConvertEntity().ToString();
//string str="<table><tr><td>品名</td><td>最高价格</td><td>最低价格</td><td>平均价格</td><td>计量单位</td><td>备注</td></tr><tr><td>青菜</td><td> </td><td> </td><td> </td><td>元/公斤</td><td> </td></tr></table>";
sw.Write(str);
sw.Close();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "GB2312";
//HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ".xlsx");
HttpContext.Current.Response.Write(sw);
HttpContext.Current.Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
HttpContext.Current.Response.End();
HttpContext.Current.Response.Close();
}相关推荐
SpringBoot下载xlsx模板,导出excel数据
此文件功能使用SpringBoot来编写,包括写好的前端和后端代码。 使用SpringBoot+POI导出excel数据。 使用SpringBoot导出excel模板文件,防止用户导入错误。 先看是否需要在下载,功能演示都放在这篇文章了:https://truedei.blog.csdn.net/article/details/105325018 下载地址:点我下载 项目结构 controller层 package edu.sdjsjxy.jc.controller; import com.alibaba.fastjson.JSONObject; import com.fasterxm
在.NET MVC中使用NPOI库实现内存流导出Excel文件指南
在构建现代Web应用程序时,选择一个合适的架构模式至关重要。.NET MVC,即Model-View-Controller,是微软公司设计的一种框架,用于帮助开发者高效地开发可维护和可扩展的Web应用。该架构强调了关注点分离的原则,通过清晰的分层来确保代码的组织性和模块化,促进了开发团队间的协作。NPOI是一个开源的.NET库,允许开发者在.NET应用程序中读取和写入Microsoft Office格式的文件,包括但不限于Excel、Word和PowerPoint。
MVC 下 EXCEL 导入导出
本人亲测,整理。下载来可以直接运行使用。所以跟大家共享一下资源
SSM 下 Excel的导入导出
在SSM下 使用POI实现Excel的导入/导入 里面还有一些方法类 可供参考
MVC导入与导出excel文件
MVC导入与导出excel文件. 作为一个共享吧。 有没有用仅供参考。 做了几年了。 技术方面请自己验证。


