protected void exportAward(DataSet dsResult)
{
if (dsResult != null)
{
string fileName = System.Web.HttpUtility.UrlEncode("任务列表", System.Text.Encoding.UTF8) + ".xls";//excel 名称
ExportDataSetToExcel(dsResult, fileName, "writered");
} }

  

 /// <summary>
///
/// </summary>
/// <param name="sourceDs">导出数据源</param>
/// <param name="fileName">excel名称</param>
/// <param name="sheetName">工作表名</param>
public void ExportDataSetToExcel(DataSet sourceDs, string fileName, string sheetName)
{
MemoryStream ms = DataSetToExcel(sourceDs, sheetName) as MemoryStream;//创建内存流
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
HttpContext.Current.Response.BinaryWrite(ms.ToArray());
HttpContext.Current.Response.End();
ms.Close();
ms = null;
}

  

    public Stream DataSetToExcel(DataSet sourceDs, string sheetName)
{ HSSFWorkbook workbook = new HSSFWorkbook();
MemoryStream ms = new MemoryStream(); //创建内存流
string[] sheetNames = sheetName.Split(',');
for (int i = 0; i < sheetNames.Length; i++)
{
HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet(sheetNames[i]); HSSFRow headerRow = (HSSFRow)sheet.CreateRow(0); //表头 headerRow.CreateCell(0).SetCellValue("序号");
headerRow.CreateCell(1).SetCellValue("任务标题");
headerRow.CreateCell(2).SetCellValue("发布人");
headerRow.CreateCell(3).SetCellValue("发布时间");
headerRow.CreateCell(4).SetCellValue("参阅人");
headerRow.CreateCell(5).SetCellValue("接收范围");
headerRow.CreateCell(6).SetCellValue("任务时间");
headerRow.CreateCell(7).SetCellValue("任务状态"); //填充表格
int rowIndex = 1;
for (int j = 0; j < sourceDs.Tables[0].Rows.Count; j++)
{
HSSFRow dataRow = (HSSFRow)sheet.CreateRow(rowIndex);
//for (int a = 0; a < sourceDs.Tables[0].Columns.Count; a++)
//{
dataRow.CreateCell(0).SetCellValue(sourceDs.Tables[0].Rows[j]["Row"].ToString());
dataRow.CreateCell(1).SetCellValue(sourceDs.Tables[0].Rows[j]["F_Title"].ToString());
dataRow.CreateCell(2).SetCellValue(sourceDs.Tables[0].Rows[j]["F_teaName"].ToString());
dataRow.CreateCell(3).SetCellValue(sourceDs.Tables[0].Rows[j]["F_CreatedDate"].ToString());
dataRow.CreateCell(4).SetCellValue(sourceDs.Tables[0].Rows[j]["F_SeePeopleName"].ToString());
dataRow.CreateCell(5).SetCellValue(sourceDs.Tables[0].Rows[j]["F_SchoolnameRange"].ToString());
dataRow.CreateCell(6).SetCellValue(Convert.ToDateTime(sourceDs.Tables[0].Rows[j]["F_StartTime"]).ToString("yyyy-MM-dd HH:mm") + "~" + Convert.ToDateTime(sourceDs.Tables[0].Rows[j]["F_EndTime"]).ToString("yyyy-MM-dd HH:mm"));
dataRow.CreateCell(7).SetCellValue(sourceDs.Tables[0].Rows[j]["taskfalg"].ToString());
//}
rowIndex++;
}
}
workbook.Write(ms);
ms.Flush();
ms.Position = 0;
workbook = null;
return ms;
}

  

NopI 导出数据的更多相关文章

  1. 使用npoi.dll导出数据到excel

    .net数据导出excel数据有多种方法,最常用的就是使用office组件,但随之而来的问题也很棘手,又要调权限又要确定是否安装office很是麻烦,最近一个项目中也有数据导出功能,随使用excel模 ...

  2. NOPI导出Excel

    NOPI导出Excel /// <summary> /// 导出的方法 Excel样式 /// </summary> /// <param name="ds&q ...

  3. CRL快速开发框架系列教程九(导入/导出数据)

    本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...

  4. Vertica 导出数据测试用例

    需求:构建简单的测试用例,完成演示Vertica导出数据的功能. 测试用例:导出test业务用户t_jingyu表中的数据. 一.初始化测试环境 二.导出数据 2.1 vsql命令说明帮助 2.2 导 ...

  5. 1.ASP.NET MVC使用EPPlus,导出数据到Excel中

    好久没写博客了,今天特地来更新一下,今天我们要学习的是如何导出数据到Excel文件中,这里我使用的是免费开源的Epplus组件. 源代码下载:https://github.com/caofangshe ...

  6. 导出数据到Excel --使用ExcelReport有感

    先看图,这是几个月前用NPOI写的导出数据到Excel,用了上百行代码,而且难控制,导出来也比较难看 excel打开的效果 下面是我用ExcelReport类库导出到Excel的操作 1.首先引用Ex ...

  7. MySQL 导出数据

    MySQL中你可以使用SELECT...INTO OUTFILE语句来简单的导出数据到文本文件上. 使用 SELECT ... INTO OUTFILE 语句导出数据 以下实例中我们将数据表 cnbl ...

  8. 使用Open xml 操作Excel系列之二--从data table导出数据到Excel

    由于Excel中提供了透视表PivotTable,许多项目都使用它来作为数据分析报表. 在有些情况下,我们需要在Excel中设计好模板,包括数据源表,透视表等, 当数据导入到数据源表时,自动更新透视表 ...

  9. Dynamics CRM导出数据到Excel

    原创地址:http://www.cnblogs.com/jfzhu/p/4276212.html 转载请注明出处 Pivot Table是微软BI的一个重要工具,所以这里讲一下Dynamics CRM ...

随机推荐

  1. Arcane Numbers 1

    Vance and Shackler like playing games. One day, they are playing a game called "arcane numbers& ...

  2. cocos2dx v3.x lua绑定分析

    打算新项目转到cocos2dx v3上了,下载代码浏览过后发现改动真是非常大,结构性调整很多. 比如tolua绑定这一块,就几乎全翻新了. 胶水代码的生成,改成了全自动式的,通过clang来分析c++ ...

  3. Java引用的四种状态

    强引用 用的最广,我们平时写代码时,new一个Object存放在堆内存,然后用一个引用指向它.它就是强引用. 如果一个对象具有强引用,那么垃圾回收期绝不会回收它,当内存空间不足,java虚拟机宁愿抛出 ...

  4. hdu1064

    #include <iostream>#include<iomanip>using namespace std; int main(){ float total_sum=0.0 ...

  5. 关于layui弹出层的使用

    Jquery必须大于1.83 layui必须是all,否则不显示 <script src="../js/jquery-1.8.3.min.js"></script ...

  6. 如何给自己的开源项目选择和添加 License

    License 的作用:开源 == 为所欲为? 开源并不等于为所欲为! 代码的用途,修改之后的代码有什么要求,开源程序对于原作者的权利和责任等等,都是需要明确的. 开源协议 License 就是这么一 ...

  7. hdu 1729 Stone Game

    Stone Game HDU - 1729 题意: 给定n个箱子,每个箱子的容量为si,每个箱子里最初有ci个石子,每次放入石子不能超过放入前的石子数的平方,谁无法继续放入石子就算输.   /* 这是 ...

  8. Object类、常用API

    Object类.常用API Object类.常用API Object类.常用API Object类.常用API Object类.常用API Object类.常用API

  9. Qt学习之网络编程(一)

    一些说明 学了有一段时间的python了,小项目做了不少,最近由于项目需要,所以要回归老本行了,开始重点突击C++和qt.python的网络爬虫系列有时间就更吧. 获取本机网络信息 在网络应用中,经常 ...

  10. Zabbix之CentOS7.3下yum安装Zabbix3.5

    Zabbix特点介绍 (此介绍来源于https://www.zabbix.com/documentation/3.4/zh/manual/introduction/features) 概述Zabbix ...