该链接有导入,导出源码,我的代码有下链接改写,完善而成的,

http://www.cnblogs.com/colder/p/3611906.html

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using System.Data;
using NPOI;
using NPOI.HPSF;
using NPOI.HSSF;
using NPOI.HSSF.UserModel;
using NPOI.POIFS;
using NPOI.Util;
using NPOI.HSSF.Util;
using NPOI.HSSF.Extractor;
using NPOI.SS.UserModel;
using System.Web.UI.HtmlControls;

private void to_excel()
{
HSSFWorkbook workbook = new HSSFWorkbook();
ISheet sheet = workbook.CreateSheet("Sheet1");
MemoryStream ms = new MemoryStream();

ICellStyle HeadercellStyle = workbook.CreateCellStyle();
HeadercellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
HeadercellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
HeadercellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
HeadercellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
HeadercellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
//字体
NPOI.SS.UserModel.IFont headerfont = workbook.CreateFont();
headerfont.Boldweight = (short)FontBoldWeight.Bold;
HeadercellStyle.SetFont(headerfont);

//用column name 作为列名
string[] temArr = { "帐号", "子帐号", "客户经理号(8位)", "开户日期(YYYYMMDD)" };
List<string> headlist = new List<string>(temArr);
int icolIndex = 0;
IRow headerRow = sheet.CreateRow(0);
foreach (var item in headlist)
{
ICell cell = headerRow.CreateCell(icolIndex);
cell.SetCellValue(item);
cell.CellStyle = HeadercellStyle;
icolIndex++;
}

ICellStyle cellStyle = workbook.CreateCellStyle();

//为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;

NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
cellfont.Boldweight = (short)FontBoldWeight.Normal;
cellStyle.SetFont(cellfont);

//建立内容行
TMSDataContext dc = new TMSDataContext();

var lctlist = dc.wd_lct_dq_import.ToList();
int iRowIndex = 1;
//int iCellIndex = 0;
foreach (var lct in lctlist)
{
IRow DataRow = sheet.CreateRow(iRowIndex);

//第1列 账号
ICell cell = DataRow.CreateCell(0);
cell.SetCellValue(lct.zh);
cell.CellStyle = cellStyle;
//第2列 子账号
cell = DataRow.CreateCell(1);
cell.SetCellValue(lct.zh_sub);
cell.CellStyle = cellStyle;
//第3列 客户经理号
cell = DataRow.CreateCell(2);
cell.SetCellValue(lct.emp_lch);
cell.CellStyle = cellStyle;
//第4列 开户日期
cell = DataRow.CreateCell(3);
cell.SetCellValue(lct.kh_rq);
cell.CellStyle = cellStyle;

iRowIndex++;
}

//自适应列宽度
for (int i = 0; i < icolIndex; i++)
{
sheet.AutoSizeColumn(i);
}
workbook.Write(ms);
Response.AddHeader("Content-Disposition", string.Format("attachment; filename=EmptyWorkbook.xls"));
Response.BinaryWrite(ms.ToArray());

workbook = null;
ms.Close();
ms.Dispose();

}

转载于:https://www.cnblogs.com/shanwater/p/5638020.html

npoi导出execl源码,vs2008实现,包括using库相关推荐

  1. unity FBX模型导出系统源码WRP FBX Exporter下载

    unity FBX模型导出系统源码WRP FBX Exporter Requires Unity 5.0.4 or  higher. Fast and easy way to export FBX f ...

  2. 小程序/app 商城 源码 发布(包括后台)

    小程序/app 商城 源码 发布(包括后台)无任何隐瞒 前端使用uniapp,后端使用thinkphp,开发简单好用的商城,可以生成为app,网站,公众号,小程序等, 这是一个直接可以商用的商城项目. ...

  3. 导出python源码的函数调用关系图的方法

    导出python源码的函数调用关系图的方法 1. pycallgraph+graphviz 2. pyreverse+graphviz 3. pycharm(推荐) 4. starUML 5. Ent ...

  4. 从源码分析Android的Glide库的图片加载流程及特点

    转载:http://m.aspku.com/view-141093.html 这篇文章主要介绍了从源码分析Android的Glide库的图片加载流程及特点,Glide库是Android下一款人气很高的 ...

  5. 一般源码安装添加的GD库 是不支持 jpeg 格式的图片的

    一般源码安装添加的GD库 是不支持 jpeg 格式的图片的,只支持如下格式 GD Support enabled  GD Version bundled (2.0.34 compatible)  GI ...

  6. android studio开发十一 Library第三方类库源码, Jar包和SO库

    原创: 发现android里面不熟悉的东西太多了,查了好多资料,终于搞清楚 Library第三方类库源码, Jar包和SO库这些都是干什么的了,怎么使用它们了. [Library第三方类库源码] Ja ...

  7. 在线客服系统源码多商户支持词库Thinkphp5.1多客服商家版

    2022最新完美运营在线客服系统源码多商户支持词库Thinkphp5.1多客服商家版源码人工客服php防黑加固源码 YID:4179684461803288

  8. 【Muduo源码剖析笔记】 网络库之Acceptor、Connector

    [Muduo源码剖析笔记] 网络库之Acceptor.Connector Acceptor typedef std::function<void (int sockfd, const InetA ...

  9. java使用freemark实现word(.doc/.docx)/pdf生成和导出(附源码和模板文件)

    freemark生成word/pdf 一. 背景 二.实现的技术选型以及遇到的坑 三.最终的效果 2.1 `.doc` word效果展示 2.1 `.docx` word效果展示 2.2 docx w ...

最新文章

  1. 百度Q3财报里的“大生意”
  2. android ffmpeg 简书,偶遇FFmpeg(三)——Android集成
  3. map中的迭代删除操作注意问题
  4. java8 垃圾收集_面试官:怎么做JDK8的垃圾收集器的调优(面试常问)
  5. Windows 2008活动目录的安装和卸载
  6. Django中ORM之或语句查询
  7. Perl 面对对象的案例理解
  8. HDU3788 ZOJ问题
  9. mysql密码攻击_MYSQL用户root密码为弱口令又一攻击方法
  10. NOIP2018 游记
  11. Linux系统安装MySQL5.7,授权远程登陆
  12. syntaxhighlighter高亮动态代码
  13. thunder链接转换普通地址下载
  14. Easyx——基于easyx的c语言简单动画入门
  15. 业务流程管理模型优化设计
  16. 【Ubuntu+ROS安装方法】
  17. 如何用计算机将图片整成手绘画,【新手教程】如何将手绘作品转变成电子档,并让其更像“作品”?...
  18. debian 安装firefox 最新版
  19. 2017年5月问题记录与总结——powerpc p1020 spi flash驱动
  20. Loadrunner 9.5 flex性能测试

热门文章

  1. oracle自增列问题i,关于oracle中自增列问题
  2. python beautifulsoup模拟点击_Python爬虫丨BeautifulSoup实践
  3. 第一个使用计算机图形学术语,计算机图形学考题
  4. input限制文字个数但是输入中文时会被切断_Python文字转换语音,让你的文字会「说话」抠脚大汉秒变撒娇萌妹...
  5. java devexpress_Coolite与DevExpress比较
  6. java 1%10_Java 操作符与运算符详解
  7. thinkphp mysql 密码加密_thinkphp框架实现mysql读写分离
  8. 使用Python,OpenCV的Meanshift 和 Camshift 算法来查找和跟踪视频中的对象
  9. 使用Python和OpenCV进行拍摄截图
  10. LabVIEW轮廓分析与比较(基础篇—8)