ExcelResult继承:ViewResult(只支持excel版本2003及兼容2003的版本)通过视图模板生成excel

	/// <summary>
/// ms-excel视图
/// </summary>
public class ExcelResult:ViewResult
{
#region 字段
private string _fileName;
#endregion #region 构造函数
public ExcelResult(string fileName, object model)
: this(null, fileName, model)
{
} public ExcelResult(string viewName, string fileName, object model)
{
this.ViewName = viewName;
this.ViewData.Model = model;
_fileName = fileName;
}
#endregion #region 重写方法
public override void ExecuteResult(ControllerContext context)
{
base.ExecuteResult(context); var response = context.HttpContext.Response;
response.ContentType = "application/ms-excel";
response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
//response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
response.Charset = "utf-8";
response.Headers.Set("Content-Disposition", string.Format("attachment; filename={0}-{1:yyyy-MM-dd}.xls", _fileName, DateTime.Now)); }
#endregion
}

  方法调用:

ActionResult 方法(){

return ExcelView("Exportinfo", "信息", cooperates.ToList());// cooperates.ToList()查询到的数据列表

}

视图页不用生成控制方法:

@model IEnumerable<Zhuoli.Model.BInfo>
@{
Layout = null; }
<table cellspacing="" cellpadding="" rules="all" border="">
<thead>
<tr>
<th>编号</th>
</tr>
</thead>
<tbody id="list-table-body">
@foreach (var item in Model)
{
<tr>
@*编号*@
<td>@item.ID</td>
</tr>
}
</tbody>
</table>

Excel导出采用mvc的ExcelResult继承遇到的问题的更多相关文章

  1. Excel导出采用mvc的ExcelResult继承遇到的问题Npoi导出

    #region 构建Excel文档 //创建Excel文件的对象 NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSS ...

  2. C# 实现NPOI的Excel导出

    技术点: 1.自定义attribute属性 2.通过反射取类及其属性的attribute属性值 3.NPOI包常用属性及方法(我也仅仅知道用到过的,陌生的要么见名知意,要么百度查) 实现功能点: Li ...

  3. 并发编程概述 委托(delegate) 事件(event) .net core 2.0 event bus 一个简单的基于内存事件总线实现 .net core 基于NPOI 的excel导出类,支持自定义导出哪些字段 基于Ace Admin 的菜单栏实现 第五节:SignalR大杂烩(与MVC融合、全局的几个配置、跨域的应用、C/S程序充当Client和Server)

    并发编程概述   前言 说实话,在我软件开发的头两年几乎不考虑并发编程,请求与响应把业务逻辑尽快完成一个星期的任务能两天完成绝不拖三天(剩下时间各种浪),根本不会考虑性能问题(能接受范围内).但随着工 ...

  4. abp框架Excel导出——基于vue

    abp框架Excel导出--基于vue 目录 abp框架Excel导出--基于vue 1.技术栈 1.1 前端采用vue,官方提供 1.2 后台是abp--aspnetboilerplate 2. E ...

  5. 二十六、【开源框架】EFW框架Winform前端开发之Grid++Report报表、条形码、Excel导出、图表控件

    回<[开源]EFW框架系列文章索引>        EFW框架源代码下载V1.2:http://pan.baidu.com/s/1hcnuA EFW框架实例源代码下载:http://pan ...

  6. 偷懒小工具 - Excel导出公共类

    说明 最近接了一个任务,就是做一个列表的Excel导出功能.并且有很多页面都会使用这个功能. 导出的Excel大体格式如图 很简单的列表,标题加背景色,然后不同类型,显示方式不一样.对齐方式不一样.不 ...

  7. Atitit.excel导出 功能解决方案 php java C#.net版总集合.doc

    Atitit.excel导出 功能解决方案 php java C#.net版总集合.docx 1.1. Excel的保存格式office2003 office2007/2010格式1 1.2. 类库选 ...

  8. .NET开发工具之Excel导出公共类

    来源:Pino晨 链接:cnblogs.com/chenxygx/p/5954870.html 说明 最近接了一个任务,就是做一个列表的Excel导出功能.并且有很多页面都会使用这个功能. 导出的Ex ...

  9. 也谈Excel导出

    吐槽 Excel导出在天朝的软件大环境下,差点成为软件开发必备.俺就遇到过,所有报表不提供导出功能,就能不验收的囧事.报表能查看能打印能形成图表已经完美,实在搞不懂导出excel有个毛用,但是公司依靠 ...

随机推荐

  1. tensorflow-Inception-v3模型训练自己的数据代码示例

    一.声明 本代码非原创,源网址不详,仅做学习参考. 二.代码 # -*- coding: utf-8 -*- import glob # 返回一个包含有匹配文件/目录的数组 import os.pat ...

  2. Linux命令行基础

    常用命令 命令 功能 pwd 打开当前所在的文件目录 ls 查看当前文件夹下的文件(不包括隐藏文件) ls -a 查看当前文件夹下的文件(包括隐藏文件) ls -al 查看当前文件夹下的文件(包括隐藏 ...

  3. How to use draggable attribute?怎样使用拖拽属性代码分享

    6.7 Drag and dropSupport: dragndropChrome for Android NoneChrome 4+iOS Safari 11.0+UC Browser for An ...

  4. go基本语法

    1. 用var来定义变量, 类型被纺织在变量名的后面. var i int 并且运行时默认初始化为二进制0 var i , y int var x string, y int2. 显示初始化值的时候, ...

  5. vs2015官方下载链接

    https://my.visualstudio.com/Downloads?q=visual%20studio%202015&wt.mc_id=o~msft~vscom~older-downl ...

  6. java mysql连接时出现的问题

    当出现Caused by: java.sql.SQLException: Unknown system variable ‘tx_isolation’ 一般是mysql-connector-java的 ...

  7. Xamarin.Forms 未能找到路径“x:\platforms”的一部分

    https://stackoverflow.com/questions/45500269/xamarin-android-common-targets-error-could-not-find-a-p ...

  8. FB面经 Prepare: Even Tree

    You are given a tree (a simple connected graph with no cycles). The tree has nodes numbered from to ...

  9. IDEA搭建scala开发环境开发spark应用程序

    通过IDEA搭建scala开发环境开发spark应用程序   一.idea社区版安装scala插件 因为idea默认不支持scala开发环境,所以当需要使用idea搭建scala开发环境时,首先需要安 ...

  10. warnings.warn("allowed_domains accepts only domains, not URLs. Ignoring URL entry %s in allowed_doma

    多页面循环爬取数据抛出如下异常 warnings.warn("allowed_domains accepts only domains, not URLs. Ignoring URL ent ...