C# NPOI 导出Execl 工具类
NPOI 导出Execl 自己单独工具类
详见代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NPOI.HPSF;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using System.Data;
using System.IO;
using System.Web;
using System.Reflection;
using System.ComponentModel; namespace NPOIHelper
{
public class NPOIHelper
{
/// <summary>
/// DataTable导出到Excel文件
/// </summary>
/// <param name="dt">源DataTable</param>
/// <param name="strHeaderText">表头文本</param>
/// <param name="strFileName">保存位置</param>
public static void ExportTableExecl(DataTable dt, string strHeaderText, string strFileName)
{
using (MemoryStream ms = Exprot(dt, strHeaderText))
{
using (FileStream fs = new FileStream(strFileName, FileMode.Create, FileAccess.Write))
{
byte[] data = ms.ToArray();
fs.Write(data, , data.Length);
fs.Flush();
}
}
} /// <summary>
/// 用于Web 导出
/// </summary>
/// <param name="dtSource">源DataTable</param>
/// <param name="strHeaderText">表头文本</param>
/// <param name="strFileName">文件名</param> public static void ExportByWeb(DataTable dtSource, string strHeaderText, string strFileName)
{
HttpContext context = HttpContext.Current; context.Response.ContentType = "application/vnd.ms-excel";
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.Charset = "";
context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName, Encoding.UTF8)); context.Response.BinaryWrite(Exprot(dtSource, strHeaderText).GetBuffer());
context.Response.End();
} /// <summary>
/// 将泛型的list 集合导出Execl
/// </summary>
/// <typeparam name="T">实体对象</typeparam>
/// <param name="list">集合</param>
/// <param name="strHeaderText">表头</param>
/// <param name="strFileName">文件名字</param>
public static void ExportToList<T>(List<T> list, string strHeaderText,string strFileName)
{
using (MemoryStream ms = ExprotToList<T>(list,strHeaderText))
{
using (FileStream fs = new FileStream(strFileName,FileMode.Create,FileAccess.Write))
{
byte[] data = ms.ToArray();
fs.Write(data,,data.Length);
fs.Flush();
}
}
} /// <summary>
/// DataTable导出到Excel的MemoryStream
/// </summary>
/// <param name="dt">数据源DataTable</param>
/// <param name="strHeaderText">表头文本</param>
/// <returns></returns>
public static MemoryStream Exprot(DataTable dt, string strHeaderText)
{
HSSFWorkbook workBook = new HSSFWorkbook(); ISheet sheet = workBook.CreateSheet(); #region 右键属性
{
DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
dsi.Company = "NPOI";
workBook.DocumentSummaryInformation =dsi; SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
si.Author = "文件作者信息";
si.ApplicationName = "创建程序信息";
si.LastAuthor = "最后保存者信息";
si.Comments = "作者信息";
si.Title = "标题信息";
si.Subject = "主题信息";
si.CreateDateTime = DateTime.Now;
workBook.SummaryInformation = si;
}
#endregion ICellStyle dateStyle = workBook.CreateCellStyle();
IDataFormat dateFormat = workBook.CreateDataFormat();
dateStyle.DataFormat = dateFormat.GetFormat("yyyy-MM-dd"); //获取列宽
int[] arrCollWidth = new int[dt.Columns.Count]; foreach (DataColumn item in dt.Columns)
{
arrCollWidth[item.Ordinal] = Encoding.GetEncoding().GetBytes(item.ColumnName.ToString()).Length;
} for (int i = ; i < dt.Rows.Count; i++)
{
for (int j = ; j < dt.Columns.Count; j++)
{
int intTemp = Encoding.GetEncoding().GetBytes(dt.Rows[i][j].ToString()).Length; if (intTemp > arrCollWidth[j])
{
arrCollWidth[j] = intTemp;
} }
} int rowIndex = ; foreach (DataRow item in dt.Rows)
{
#region 新建表 填充表头 列头 样式
{
if (rowIndex == || rowIndex == )
{
if (rowIndex != )
{
sheet = workBook.CreateSheet();
} #region 表头及样式
{
IRow headerRow = sheet.CreateRow();
headerRow.HeightInPoints = ;
headerRow.CreateCell().SetCellValue(strHeaderText); //填充填表 ICellStyle headerStyle = workBook.CreateCellStyle();
headerStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
IFont font = workBook.CreateFont();
font.FontHeightInPoints = ;
font.Boldweight = ;
headerStyle.SetFont(font); headerRow.GetCell().CellStyle = headerStyle;
sheet.AddMergedRegion(new CellRangeAddress(, , , dt.Columns.Count - ));
// headerRow.Dispose();
}
#endregion #region 列头及样式
{
IRow headRow = sheet.CreateRow();
ICellStyle headerStyle = workBook.CreateCellStyle();
headerStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; IFont font = workBook.CreateFont();
font.FontHeightInPoints = ;
font.Boldweight = ;
headerStyle.SetFont(font); foreach (DataColumn cl in dt.Columns)
{
headRow.CreateCell(cl.Ordinal).SetCellValue(cl.ColumnName);
headRow.GetCell(cl.Ordinal).CellStyle = headerStyle; //设置列宽
sheet.SetColumnWidth(cl.Ordinal, (arrCollWidth[cl.Ordinal]+)*);
}
}
#endregion rowIndex = ;
}
}
#endregion #region 填充内容
{ IRow row = sheet.CreateRow(rowIndex);
foreach (DataColumn column in dt.Columns)
{
ICell cell = row.CreateCell(column.Ordinal); string drValue = item[column].ToString(); switch (column.DataType.ToString())
{
case "System.String":
cell.SetCellValue(drValue);
break; case "System.DateTime":
DateTime dateV;
DateTime.TryParse(drValue, out dateV);
cell.SetCellValue(dateV); cell.CellStyle = dateStyle;
break; case "System.Boolean":
bool boolV;
bool.TryParse(drValue, out boolV);
cell.SetCellValue(boolV);
break; case "System.Int16":
case "System.Int32":
case "System.Int64":
case "System.Byte":
int intV = ;
int.TryParse(drValue, out intV);
cell.SetCellValue(intV);
break; case "System.Decimal":
case "System.Double":
double doubleV = ;
double.TryParse(drValue, out doubleV);
cell.SetCellValue(doubleV);
break; case "System.DBNull":
cell.SetCellValue("");
break;
default:
cell.SetCellValue("");
break;
}
} }
#endregion rowIndex++;
} using (MemoryStream ms = new MemoryStream())
{
workBook.Write(ms);
ms.Flush();
ms.Position = ;
//sheet.Dispose();
//workBook.Dispose();
return ms;
} } /// <summary>
/// 将list 集合导处 Execl
/// </summary>
/// <param name="list">泛型集合</param>
/// <param name="strHeaderName">表头名字</param>
/// <returns></returns>
public static MemoryStream ExprotToList<T>(List<T> list, string strHeaderName)
{ HSSFWorkbook workbook = new HSSFWorkbook();
ISheet sheet = workbook.CreateSheet(); //创建样式 ICellStyle cellStyle = workbook.CreateCellStyle();
IDataFormat dataFormat = workbook.CreateDataFormat();
cellStyle.DataFormat = dataFormat.GetFormat("yyyy-MM-dd"); //IRow headerRow = sheet.CreateRow(0);
//headerRow.CreateCell(0).SetCellValue(strHeaderName); //表头样式
IRow headerRow = sheet.CreateRow();
headerRow.HeightInPoints = ;
headerRow.CreateCell().SetCellValue(strHeaderName); //填充填表 ICellStyle headerStyle = workbook.CreateCellStyle();
headerStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
IFont font = workbook.CreateFont();
font.FontHeightInPoints = ;
font.Boldweight = ;
headerStyle.SetFont(font); headerRow.GetCell().CellStyle = headerStyle;
sheet.AddMergedRegion(new CellRangeAddress(, , , list[].GetType().GetProperties().Length - )); IRow rows = sheet.CreateRow(); //获取list属性值
PropertyInfo[] propertyInfo = list[].GetType().GetProperties(); #region 获取 实体 中的 [DisplayName("姓名")]
{
//获取 实体 中的 [DisplayName("姓名")] Type entity = list[].GetType(); for (int i = ; i < propertyInfo.Length; i++)
{
var pName = entity.GetProperty(propertyInfo[i].Name.ToString()).GetCustomAttribute<DisplayNameAttribute>(); rows.CreateCell(i).SetCellValue(pName.DisplayName);
} }
#endregion #region 获取实体的属性值
{ //for (int i = 0; i < propertyInfo.Length; i++)
//{
// rows.CreateCell(i).SetCellValue(propertyInfo[i].Name.ToString());
//}
}
#endregion //填充内容
int propertyIndex = ; foreach (var item in list)
{
IRow row = sheet.CreateRow(propertyIndex); for (int i = ; i < propertyInfo.Length; i++)
{
var obj = propertyInfo[i].GetValue(item, null); row.CreateCell(i).SetCellValue(obj.ToString());
} propertyIndex++;
} //宽度自适应
for (int i = ; i < list.Count; i++)
{
sheet.AutoSizeColumn(i);
} using (MemoryStream ms = new MemoryStream())
{
workbook.Write(ms);
ms.Flush();
ms.Position = ;
return ms;
} } /// <summary>
/// 读取Execl 表格
/// </summary>
/// <param name="fileName">文件路径</param>
/// <returns></returns>
public static DataTable GetReaderExecl(string fileName)
{
DataTable dt = new DataTable(); HSSFWorkbook workBook; using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
workBook = new HSSFWorkbook(fs);
} ISheet sheet = workBook.GetSheetAt();
System.Collections.IEnumerator rows = sheet.GetRowEnumerator(); IRow headerRow = sheet.GetRow();
int cellCount = headerRow.LastCellNum; for (int i = ; i < cellCount; i++)
{
ICell cell = headerRow.GetCell(i);
dt.Columns.Add(cell.ToString());
} for (int j = (sheet.FirstRowNum + ); j <= sheet.LastRowNum; j++)
{
IRow row = sheet.GetRow(j); DataRow dr = dt.NewRow(); for (int i = row.FirstCellNum; i <= cellCount; i++)
{
if (row.GetCell(i) != null)
{
dr[i] = row.GetCell(i).ToString();
}
} dt.Rows.Add(dr);
} return dt;
} }
}
解析一下 泛型集合导出Execl 中的一个问题
第一步:首先定义一个实体类
public class People
{
[DisplayName("姓名")]
public string name { get; set; } [DisplayName("年龄")]
public string Age { get; set; } [DisplayName("性别")]
public string Sex { get; set; }
}
第二步:直接调用
NPOIHelper.NPOIHelper.ExportToList<People>(this.GetLists(), "list","list.xls");
这样导出结果是这样的
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAxkAAAEDCAIAAADWU158AAAaGElEQVR4nO3d3Y9k510n8Ppv+j9oTd20VDesWIfRot1VRIScCS8FCAYFAkgrIO5ZaXdRsCgRVL7Amx6hBbTxTczbmSQEi+xGTEBRpyaJ6SQFqyibxhsTJ6Qce2LM6nDxjLtPn7eqrvPy9Kn6fPRV1K50OydSP6e+/TunnjM6+4fHIiIiIrJdRj/97MdEREREZLuMTpLT+rz1L/9f5CZkNT986yv3RSRKVvPD6CcBkZuQYjUavfyNVVVe/Pzjk+T0zbfeFrkJWc0Pv3/2uyISJav5YfSTgMhNSLEajT76mW9WJXSp7z3+Z5GbkNX88PsvPyciUbKaH0Y/CYjchBSr0fou9d033pJG+Yv/fDB53+98JfZhDD+r+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nRweToYHJ098GWz5BJC6XKGqMLF13q8qXcM2SWs7HNpaAbxS619mvYSSVd6kmFenDvYHLn2Ufb7Htu5dCP0KUyL4TtOS9aUzIdZTfutAc6tEmXgqCkSz18Upu++uydktHU5vueQ9eyv75hAjWeTi/nUsk0U58KDz0GmnGND4Ka+6Veult2mW/Da3zQgytdKkmWaU1lysyogDaYS0FQ2aUePn/n4M79h+vul7ryk/4WoV8lHyOq6FIecwyt06UgKO9SD5+/c7DBs42LK6TmfimDX1q3YZdazsZmUtA61/ggKLtf6vk7pXedb36Nz8qhH5t0qeVs7K5z6ELV/lLeAtg3JV2qaiK1+ef4UmuJXqztUiZS0J3sAqwZShlNsfNKulTVREqX4qZZ06XcJAVdKp1LVd3j0f3hQDSlc6mjg+rtOjffE8HioWv1XSpsNpVlQgUtKnn/qDjteztgtzV9hkxueLv5XedmvzTncWAQUfEaX+4bnOTZE55tzIDpUhCRBQiBLsWAOZVDRBYgBCVd6iQ5rc/i7FxERERESmMuxWAs/FkM8ViAEBTXgi7FYDiVQ0QWIAS6FAPmVA4RWYAQlHSpdzaXKn+MjC7FzeFUDhFZgBCUdKknFerBvdKHyehS3BxO5RCRBQhBzTW+l+6WjaZ0KW4Op3KIyAKEoLJLPXz+zsGd+w/NpbjBnMohIgsQgrIu9ej+U+6XYgicyiEiCxCC6mt87pfixnMqh4gsQAjcL8WAOZVDRBYgBLoUA+ZUDhFZgBCUdKkn1/Ue3X/KvefcbE7lEJEFCEHNXp0lN0vpUtwoTuUQkQUIgWfIMGBO5RCRBQiBLsWAOZVDRBYgBLoUA+ZUDhFZgBCUdKmT5LQ+i7NzERERESmNuRSDsfBnMcRjAUJQXAu6FIPhVA4RWYAQ6FIMmFM5RGQBQlBcC/8KscFu2Dje93IAAAAASUVORK5CYII=" alt="" />
表头显示的是 中文的 也就是实体类中的DisplayName 的值;如果不想使用这个值,想使用属性值得 也是可以的;将上面的代码 注释一下,将下面的 的代码解注一下 就OK 了
修改的代码如下:
/// <summary>
/// 将list 集合导处 Execl
/// </summary>
/// <param name="list">泛型集合</param>
/// <param name="strHeaderName">表头名字</param>
/// <returns></returns>
public static MemoryStream ExprotToList<T>(List<T> list, string strHeaderName)
{ HSSFWorkbook workbook = new HSSFWorkbook();
ISheet sheet = workbook.CreateSheet(); //创建样式 ICellStyle cellStyle = workbook.CreateCellStyle();
IDataFormat dataFormat = workbook.CreateDataFormat();
cellStyle.DataFormat = dataFormat.GetFormat("yyyy-MM-dd"); //IRow headerRow = sheet.CreateRow(0);
//headerRow.CreateCell(0).SetCellValue(strHeaderName); //表头样式
IRow headerRow = sheet.CreateRow();
headerRow.HeightInPoints = ;
headerRow.CreateCell().SetCellValue(strHeaderName); //填充填表 ICellStyle headerStyle = workbook.CreateCellStyle();
headerStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
IFont font = workbook.CreateFont();
font.FontHeightInPoints = ;
font.Boldweight = ;
headerStyle.SetFont(font); headerRow.GetCell().CellStyle = headerStyle;
sheet.AddMergedRegion(new CellRangeAddress(, , , list[].GetType().GetProperties().Length - )); IRow rows = sheet.CreateRow(); //获取list属性值
PropertyInfo[] propertyInfo = list[].GetType().GetProperties(); #region 获取 实体 中的 [DisplayName("姓名")]
{
//获取 实体 中的 [DisplayName("姓名")] //Type entity = list[0].GetType(); //for (int i = 0; i < propertyInfo.Length; i++)
//{
// var pName = entity.GetProperty(propertyInfo[i].Name.ToString()).GetCustomAttribute<DisplayNameAttribute>(); // rows.CreateCell(i).SetCellValue(pName.DisplayName);
//} }
#endregion #region 获取实体的属性值
{ for (int i = ; i < propertyInfo.Length; i++)
{
rows.CreateCell(i).SetCellValue(propertyInfo[i].Name.ToString());
}
}
#endregion //填充内容
int propertyIndex = ; foreach (var item in list)
{
IRow row = sheet.CreateRow(propertyIndex); for (int i = ; i < propertyInfo.Length; i++)
{
var obj = propertyInfo[i].GetValue(item, null); row.CreateCell(i).SetCellValue(obj.ToString());
} propertyIndex++;
} //宽度自适应
for (int i = ; i < list.Count; i++)
{
sheet.AutoSizeColumn(i);
} using (MemoryStream ms = new MemoryStream())
{
workbook.Write(ms);
ms.Flush();
ms.Position = ;
return ms;
} }
效果图:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAg8AAAELCAIAAADRPvJ+AAAY+UlEQVR4nO2dXY8b13mA+Tv8B+g73xGrGwJz48KmtaiRtIKVDxBNQrtAtjWsdZAWaFe8iC+SbRYoTF10bTFB2rTZFojd1KTruot+GNkkMORZR4riVWMYruQP2ZIiKpKiqsX2glzOma8zM7ucc94z8zx4EawYZjrFvHMevufMnLdx8YO7BEEQBKGPhvUzIAiCIORH46n1HxIEQRCEPhpnR+eOGJNB6947Q6JKwTUl9EGGyIzJoHXvf/+vpGhcuDw5Srz01t3JoPXbi39FVCm4poQ+yBCZMRm07ty7X1I0fvDGx0eJmS0unCGqFFxTQh9kiMyYDFq/ufs/JcVibHH3/F9WP77/+ab32JnXbZ+GkajLNdXH63+47LWboahLAmRGRTJEvcTPft3++Rw5JoPWzdv3FhzvfPe412567QXZ4u1vVz1On/lce/XZk81nV22fiYmoxzXNin95ctk7+ar6yd+cbEY+qWtUIUNCV/P0mc+1K3B3TwatG7fuLjguDo97/X+8dfcwtvjJO7+O2OLO7jcrHq99Zdl7Yjz9T+snU37U4ppmRsLlfmbV65x5zfaJCQj3M+SZVa+9+tfKJ699Zdn9izsZtD69eWfBcWH4mHf6pZt3Ctvixxev3/3tvagt3vpGteMX33q0ufpHd976xni1vfytP7V+PmVHHa5pdvzzHyx7J8bqJ987MU0DwvkM+d6JZuTiViImg9bVG7cXHOfPPuad/uGN28Vs8caFa5Nbdya37kRscftcv9Lx1VXvkcGr/dvn+re/+/vNk90L9k+p3KjBNc0Rr3Zj6xbt5W9+zf6JCQjnM6SiN/Jk0Prw2q0Fx9svdrzT/3DtVgFb/MfPP712fTKNqC3e/LMqx3c+2zz5xQuzfz616rVXv2P7lEqO6l/TPDH64rL32XH0k0cGI9snJiCcz5DQTV2dmAxaVz6Z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POI 导出Execl 工具类的更多相关文章
- 导入导出Excel工具类ExcelUtil
前言 前段时间做的分布式集成平台项目中,许多模块都用到了导入导出Excel的功能,于是决定封装一个ExcelUtil类,专门用来处理Excel的导入和导出 本项目的持久化层用的是JPA(底层用hibe ...
- javaEE开发之导出excel工具类
web开发中,一个系统的普通需求也包含导出excel,一般採用POI做统计报表导出excel. 导出excel工具类: import java.io.FileOutputStream; import ...
- Java 通过Xml导出Excel文件,Java Excel 导出工具类,Java导出Excel工具类
Java 通过Xml导出Excel文件,Java Excel 导出工具类,Java导出Excel工具类 ============================== ©Copyright 蕃薯耀 20 ...
- NPOI导出Excel帮助类
工具类 using System; using System.Collections.Generic; using System.Data; using System.IO; using System ...
- 导出Excel工具类
import java.io.OutputStream; import java.lang.reflect.Method; import java.text.SimpleDateFormat; imp ...
- java导出excel工具类
java导出excel须要使用HSSFWorkbook这个类,须要导入poi-3.6-20091214.jar 工具类调用例如以下: package com.qlwb.business.util; i ...
- Java XSSF 导出excel 工具类
参数解释: title:导出excel标题.headers 导出到excel显示的列头. columns 对应数据库字段 .list 导出数据1.pox中添加依赖 <dependency> ...
- 使用POI导出EXCEL工具类并解决导出数据量大的问题
POI导出工具类 工作中常常会遇到一些图表需要导出的功能,在这里自己写了一个工具类方便以后使用(使用POI实现). 项目依赖 <dependency> <groupId>org ...
- JXL导出Excel工具类
将Excel中的数据读取到List<Map<String, Object>>集合中 package com.mvc.util; import java.io.File; ...
随机推荐
- 队列(循环队列)----C语言
线性结构:有且只有一个根节点,且每个节点最多有一个直接前驱和一个直接后继的非空数据结构 非线性结构:不满足线性结构的数据结构 队列 队列一般分为两类:链式队列和顺序队列 链式队列---链式队列即用链表 ...
- Android 美学设计基础 <3>
本期接着对Android的美学设计的分享. 1.3 Light and shadows 光学与阴影 1.3.1 Light 在素材设计的环境中,我们会用虚拟的光来照亮UI界面.主灯光会产生尖锐,有方向 ...
- [JavaScript] iframe加载完成事件
//iframe加载完成后,对其子元素进行操作 var iframe = document.getElementById("re-img"); if (iframe.attachE ...
- maven项目发布到tomcat后没有lib目录解决方案
maven项目放入tomcat中时,总是报错,而且这些jar都是真实存在的,错误如下: maven eclipse tomcat java.lang.ClassNotFoundException: o ...
- vue学前班004(基础指令与使用技巧)
我学vue 的最终目的是为了 做apicloud 和vue 的开发 作为配合apicloud的前端框架使用 所以项目用不到的会暂时不介绍. (强烈建议 官网案例走一遍) 基础指令的学习(结合aui ...
- C#使用 RNGCryptoServiceProvider 生成强随机字符串
为了生成更加可靠的随机数,微软在System.Security.Cryptography命名空间下提供一个名为system.Security.Cryptography.RNGCryptoService ...
- 设置pip源头地址
更新pip源 1 . 可以直接在pip时加入参数 比如: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple mysqldb 2 . 修改默 ...
- Python单行注释与多行注释
>>> print "hello,world"hello,world>>> 2+24#单行注释 """每行代码的后 ...
- 如何虚拟机里安装Win8操作系统
不多说,直接上干货! Windows Server 2003.2008.2012系统的安装 推荐网址:打开MSDN网站(http://msdn.itellyou.cn ) 关于给电脑换系统,很多人会花 ...
- 微服务Kong(九)——认证参考
客户端访问上游API服务,通常由Kong的认证插件及其配置参数来控制. 通用认证 一般情况下,上游API服务都需要客户端有身份认证,且不允许错误的认证或无认证的请求通过.认证插件可以实现这一需求.这些 ...