将数据导出到Excel,供用户下载是经常要使用到的一个功能,我这里进行了一些封装,目前已满足项目中导出的需求,使用DataReader导出Excel,支持自定义多表头,使用委托处理字段格式化及字段值的计算;

导出执行的代码如下:

        /// <summary>
/// 将DataReader数据写入到 excel book 中
/// 一般数据量小的导出用这个就可以啦
/// </summary>
/// <param name="dataReader"></param>
/// <param name="book">Excel Book</param>
/// <param name="excelName">excelName文件名字</param>
/// <param name="sheetSize">每个Sheet放多少条记录</param>
/// <param name="excelHeaderModels">Excel表头实体,Select字段可以从这里获取</param>
/// <param name="func">字段格式化委托函数</param>
/// <param name="funcCalc">字段的值计算委托函数</param>
/// <returns></returns>
public Hashtable CommonDataWrite2Sheet(IDataReader dataReader, IWorkbook book, string excelName, int sheetSize, List<ExcelHeaderModel> excelHeaderModels = null, Func<string, object, string> func = null, Func<string, object, IDataReader, object> funcCalc = null)
{
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, BusinessSystemInfo.ExportDir, DateTime.Now.ToString(BaseSystemInfo.DateFormat));
string fileName = Path.Combine(filePath, excelName);
//创建表头
int totalCount = ;
//表头的要去掉 否则默认的是65535条记录 一个表头 所以从1开始
if (excelHeaderModels != null)
{
totalCount = excelHeaderModels.Max(c => c.RowStart) + ;
}
Hashtable ht = new Hashtable();
//给book 创建Sheet
int sheetIndex = ;
string sheetName = "sheet";
ISheet sheet = book.CreateSheet(sheetName + sheetIndex);
//在创建的sheet里面创建表头
CreateHeader(dataReader, book, excelHeaderModels, sheet);
//写入到book中 逐行
while (dataReader.Read())
{
// 输出的总数量大于每页数量(如65535),换一页写入 2003版本的才会要求限制每sheet放65535条记录
if (book.GetType() == typeof(HSSFWorkbook))
{
if (totalCount > sheetSize)
{
//换一页写
sheetIndex++;
totalCount = ;
sheet = book.CreateSheet(sheetName + sheetIndex);
CreateHeader(dataReader, book, excelHeaderModels, sheet);
}
}
//创建Excel的行这一行是sheet创建的第rowIndex++行
IRow excelRow = sheet.CreateRow(totalCount);
for (int i = ; i < dataReader.FieldCount; i++)
{
//在rowIndex++行的给第j列 写入 dt的第i行第j列的值
ICell cell = excelRow.CreateCell(i);
string colName = dataReader.GetName(i);
object value = dataReader.GetValue(i);
if (funcCalc != null)
{
value = funcCalc(colName, value, dataReader);
}
SetCellValue(func, cell, value, colName);
}
//自动调整单元格大小 有些耗时
//for (int i = 0; i < dataReader.FieldCount; i++)
//{
// sheet.AutoSizeColumn(i,true);
//}
totalCount++;
} // book写入到文件中
WriteToFile(book, fileName); //获取扩展名
//string fileExt = Path.GetExtension(fileName);
//using (ZipFile zip = ZipFile.Create(fileName.Replace(fileExt, ".zip")))
//{
// zip.BeginUpdate();
// zip.SetComment("这是我的压缩包");
// zip.Add(fileName); //添加一个文件
// zip.CommitUpdate();
//} fileName = fileName.Replace(AppDomain.CurrentDomain.BaseDirectory + "", "");
ht.Add("Code", "");
ht.Add("Detail", "数据导出完毕,请下载。");
ht.Add("fileName", fileName);
ht.Add("Count", totalCount);
return ht;
}
WriteToFile 将book写入到文件的方法,注意,这里使用了 ms.ToArray()。
        /// <summary>
/// Excel book写入到Excel文件
/// </summary>
/// <param name="book"></param>
/// <param name="fileName"></param>
/// <returns></returns>
private bool WriteToFile(IWorkbook book, string fileName)
{
bool result = true;
try
{
using (MemoryStream ms = new MemoryStream())
{
string filePath = Path.GetDirectoryName(fileName);
if (filePath != null && !Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
book.Write(ms);
var buf = ms.ToArray();
using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
fs.Write(buf, , buf.Length);
fs.Flush();
}
}
}
catch (Exception e)
{
LogHelper.WriteErrorLog(e.Message, e);
result = false;
}
finally
{
GC.Collect();
}
return result;
}

ExcelHeaderModel 是定义的表头实体,支持自定义多表头,如下:

    /// <summary>
/// 导出配置
///
/// 修改纪录
///
/// 2015-12-19版本:1.0 SongBiao 创建文件。
///
/// <author>
/// <name>SongBiao</name>
/// <date>2015-12-19</date>
/// </author>
/// </summary>
[Serializable]
public class ExcelHeaderModel
{
/// <summary>
/// 数据库里面的字段名称
/// </summary>
public string SrcName { get; set; } /// <summary>
/// 名称
/// </summary>
public string Name { get; set; } /// <summary>
/// 行开始
/// </summary>
public int RowStart { get; set; } /// <summary>
/// 行结束
/// </summary>
public int RowEnd { get; set; } /// <summary>
/// 列开始
/// </summary>
public int ColStart { get; set; } /// <summary>
/// 列结束
/// </summary>
public int ColEnd { get; set; } /// <summary>
/// 是否显示在表头 有些字段不需要显示 但是需要用来做计算
/// </summary>
[DefaultValue(false)]
public bool Hidden { get; set; }
}

Controller中的业务调用

        /// <summary>
/// 导出操作,支持导出当前页,导出全部,导出文件格式excel2003,excel2007及以上
/// </summary>
/// <param name="searchModel"></param>
/// <param name="pager"></param>
/// <param name="sort"></param>
/// <param name="direction"></param>
/// <param name="isPage">true:导出当前页,false:导出全部</param>
/// <returns></returns>
[CustomerResource("ExportData")]
public ActionResult ExportData(PriceSearchEntity searchModel, QuiGridPager pager, string sort, string direction,bool isPage)
{
PriceManager priceManager = new PriceManager(BusinessDbHelper, UserInfo);
// 使用DataReader导出
IDataReader dr ;
//要导出的字段
string selectField = GetExportField();
string tableName = PriceEntity.TableName + " A";
// 导出当前页
if (isPage)
{
dr = priceManager.ExecuteReaderByPage(searchModel,tableName, pager, sort, direction, selectField);
}
else
{
dr = priceManager.ExecuteReader(searchModel, tableName, sort, direction, selectField);
}
using (dr)
{
IWorkbook book = new HSSFWorkbook();
// 2007的导出
// IWorkbook book = new XSSFWorkbook();//.xlsx string fileName = UserInfo.NickName+"_数据导出-" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls"; // GetSelectField()
// 导出的文件自动压缩
// var hashTable = new ExportHelper().DataWrite2Excel(dr, book, fileName, 5, 65530, null, null, null); //一般用这个
var hashTable = new ExportHelper().CommonDataWrite2Sheet(dr, book, fileName, );
hashTable.Add("TotalTime", CalcTimeSpan(StartTime));
return Json(hashTable, JsonRequestBehavior.AllowGet);
}
}

这里使用了通用权限系统的权限控制功能及底层的数据访问功能,解决导出权限控制的问题。

代码里可根据需要控制输出的文件使用Excel2003还是Excel2007的文件格式。

前端导出完成展示的效果:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXcAAADXCAIAAABuyYbzAAAVYElEQVR4nO2d74scx5nH968IRkoCIWAImDiWo8gaEQZsDDHdsl/ci7xpOnCsk0086fOZ4Mg7mCZw0eXuNBajF0vEkSOyJa1DPLE2zgo5cWSt10QxkdFGyiIt8V4coj1kr+TVWN7xsvti7kXNVFdXV1VXz3T1j5nvhwdpprv6x/b085mnq3/MRMsAx48fNzFbIGMcNvg4/I2jyoSJmWKHyJhx2ODHQWmBZUYBbHBQZExZBmSMic8RgFQwYhkAAKDAMgAAs8AyAACzwDIAALPAMgAAs8AyAACzwDIAALPAMgAAs8AyAACzwDIAALPAMgAAs8AyAACzwDIAALPAMgAAs0zk/cQCAMCIg1oGAGAWWAYAYBZYBgBgFlgGAGAWWAYAYJYsLHNg8jQCgShUZJD4FFgGgRjHyCDxKbAMAjGOkUHiU2AZBGIcI4PEp8AyCMQ4RgaJT5n4jt8yHblvUAQCwUUGiU9j4qcvvWI6ct+gCASCiwwSnwYsg0CMY8AyCATCbMAyCARCHA99+xfC4XunknWAwjIIBEIQXz208Pybdx78/m+44XuePudfuPPA9KL+rGAZBALBx/4nX/7x+Vutla1/e/PW3qd+TYfvefpc4+LHrZWt539/e993dNMNlhkwut1ut9ulr2/d6bBD2Ga37nSik8hmpbPEboTcd0rE6MXe2pmji+utla0fvfHhvqnWgcnTD/zruaN/vNta2XrhD3f2ePP6s4JlehFNXVkycwNfOrtMVcI1o6Poa7VlFAuNNuMGxv4hue+1iNLF3u/+6siFm69c36rPrz347PkXLn78yvWt5sU7X/mXs4nmA8sIQictuVSnBUu0mX4tI9OKsBkMgsgg9k298u+//b/Ty5+SeOEP7fuffj3pTDK1zOQP/tN0pLJlFakrqxS4nI8OpLWMrFm0gWJuXXktg0CkG3ufnv/Znz/9nz9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ZMoG0SQQ2V0GAZcoE0iYR2FwFIYtfsAUAjDMTJn58Gxji6NGjea9CmcDmKgiwTJlA2iQCm6sgwDJlAmmTCGyuggDLlAmkTSKwuQoCLFMmkDaJwOYqCLBMmUDaJAKbqyDAMmUCaZMIbK6CAMuUCaRNIrC5CsJEq9X0bNtrBoN8N3jru8IH/jC4fjAlnRM/S5AOaacN/aibnu16ns1/uPRD9F3mg256NvupMwRjIm2ank1mJ9mlJHMcisjmYndt4VrSwciINJlotcgeQLYN3RcE9Lc191E1ozundGcFw2HCMr5n254fpJsg83y34vqyz5lLKpllWv2dy3Oju4PcW0MxqGWQESmjfLp4+BOQbFMGgbmbnmdg9xlXDFuG/552/RabcH2S1TKhMihox8w9JLk0kVpG4AHba2r4ARkxEEy/jHjnUVeI/RpYXnc2PXe8vG0S45ZhsqW3O/gusUGzKU5B1w/nZsgyvtv/2vbd3ijp/mRAM+zmYpdLFxVTQyEjUkJRy5DtRDcY3eTBvth7pSyo6ZYHw5OJZXpfu2yK+W6l4nqeTZRie81eUz6bQrUM/8FHiiJJLqYHv7kinSNRjSirGWTEgOjUMv3StrdpRNu09yGQL76+rHv7sNk9aazIxzK+W+kNkGZeD3W/THTp2Vqm/weI+rn5v6Q/ATIiDZT9MsHXFfs9xO5tgZObnu36TDFpe03ftV13/DapQVK2TNOzXb8psAzJjN4RkzgD5TPkXkWbZPb1Ht5cvmvbtu01GblxaxnfbYuMGAitWsZ1xfuA79oec7jeN3erJ29V9zwYhEws08vCJh3k95qJEy90WMX1y4RfZn42l91cvZwPeok0JIeMSIn/Bw8F2mG3YqVGAAAAAElFTkSuQmCC" alt="" />

通用的C#导出Excel 支持2003及2007以上版本的更多相关文章

  1. 润乾报表新功能–导出excel支持锁定表头

     在以往的报表设计中,锁定表头是会经常被用到的一个功能,这个功能不仅能使浏览的页面更加直观,信息对应的更加准确,而且也提高了报表的美观程度.但是,很多客户在将这样的报表导出excel时发现exce ...

  2. 一个通用的DataGridView导出Excel扩展方法(支持列数据格式化)

    假如数据库表中某个字段存放的值“1”和“0”分别代表“是”和“否”,要在DataGridView中显示“是”和“否”,一般用两种方法,一种是在sql中直接判断获取,另一种是在DataGridView的 ...

  3. NPOI 导入导出excel 支持 03 07

    因为微软的office成本太高了,所以开发项目的时候电脑上没安装office,而是安装了wps.但开发语言用的是C#,所以直接调用微软的office组件是很方便的,但一方面慢,一方面成本高,所以从网上 ...

  4. (gridcontrol等)通用导出excel z

    关于DevExpress Winform 的所有可打印控件的导出excel 的通用方法,并且解决DevExpress控件自带的方法存在的缺陷问题 1.解决GridControl自带方法不能导出图片: ...

  5. C#用Infragistics 导入导出Excel(一)

    最近项目中有数据的导入导出Excel的需求,这里做简单整理. 公司用的是Infragistics的产品,付费,不需要本地安装Office. 有需要的朋友可以下载 Infragistics.2013.2 ...

  6. C#用Infragistics 导入导出Excel

    最近项目中有数据的导入导出Excel的需求,这里做简单整理. 公司用的是Infragistics的产品,付费,不需要本地安装Office. 有需要的朋友可以下载 Infragistics.2013.2 ...

  7. NPOI导入导出EXCEL通用类,供参考,可直接使用在WinForm项目中

    以下是NPOI导入导出EXCEL通用类,是在别人的代码上进行优化的,兼容xls与xlsx文件格式,供参考,可直接使用在WinForm项目中,由于XSSFWorkbook类型的Write方法限制,Wri ...

  8. 写一个通用的List集合导出excel的通用方法

    前几天要做一个数据导出Excel 我就打算写一个通用的. 这样一来用的时候也方便,数据主要是通过Orm取的List.这样写一个通用的刚好. public static void ListToExcel ...

  9. JAVA实现导出excel功能,封装通用导出工具类

    引入maven <!--excel导出--> <dependency> <groupId>net.sourceforge.jexcelapi</groupId ...

随机推荐

  1. 安卓投屏助手(B1358)之辅助调试

    Android远程桌面助手的中文版——安卓投屏助手正式上线.安卓投屏和远程控制的软件其实已经非常多了,如Vysor.Total Control.Mobizen.ApowerMirror.TeamVie ...

  2. android---EventBus的简单使用(一)

    是什么: 就是用来发消息通信的 怎么用: 定义事件:(消息体) public class MessageEvent { /* Additional fields if needed */ } 准备订阅 ...

  3. C语言货架02

    第1章 程序设计和C语言  最简单的C语言程序举例 #include<stdio.h> int main() { printf("这是一个C程序\n"); : } C语 ...

  4. [20190423]那个更快的疑问3.txt

    [20190423]那个更快的疑问3.txt --//前一阵子,做了11g在单表单条记录唯一索引扫描的测试,摘要如下:--//参考链接:http://blog.itpub.net/267265/vie ...

  5. shell 中 if then语句中会跟着-ne -ge之类的参数的含义

    if [ 1 -ne 1 ];then...fi这是指当1不等于1时执行then后的语句 -eq:等于-ne:不等于-le:小于等于-ge:大于等于-lt:小于-gt:大于

  6. Docker-Dockerfile及基本语法

    Dockerfile的作用是通过它可以生成自定镜像,先介绍几个基本的docker命令. [docker镜像相关的命令]docker search 镜像名: 搜索镜像docker pull 镜像名: 镜 ...

  7. ASP.NET实现二维码

    using System;using System.Collections.Generic;using System.Drawing;using System.Linq;using System.Te ...

  8. iOS NFC

    #import <CoreNFC/CoreNFC.h> @interface ViewController ()<NFCNDEFReaderSessionDelegate> @ ...

  9. VirtualBox Network Config

    Sharing Host VPN with VirtualBox guest After looking for this solution everywhere, I finally found a ...

  10. CTF杂项之音频隐写

    题目来自bugku 二话不说,直接上图 由题目可以看出,这题需要用到一个KEY,加上又是一段音频,很容易联想到一个著名的音频隐写解密软件Mp3stego 直接上工具 ok,成功Get Flag