//导出全部

  expertPara = GetExpetPara();

  expertPara.BeginIndex = pager.CurrentPageIndex;

  expertPara.EndIndex = int.MaxValue;

  DataSet ds = ExpertBLL.GetPriMngExpertDate(expertPara);

  DataTable dt = ds.Tables[0];

  //判断加载哪个模板

  string tempath = "~/Templates/专家录入管理表.xls";

  //1、获取数据。

  using (FileStream file = new FileStream(HttpContext.Current.Server.MapPath(tempath), FileMode.Open, FileAccess.Read))

  {

  string ReportFileName = Server.MapPath("out.xls");

  HSSFWorkbook hssfworkbook = new HSSFWorkbook(file);

  HSSFSheet sheet1 = hssfworkbook.GetSheetAt(0) as HSSFSheet;

  sheet1.ForceFormulaRecalculation = true;

  sheet1.IsPrintGridlines = true;

  sheet1.DisplayGridlines = true;

  HSSFCellStyle _style = sheet1.Workbook.CreateCellStyle() as HSSFCellStyle;

  _style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;

  _style.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;

  int rowIndex = 0;

  {

  rowIndex = 2;

  int i = 1;

  foreach (DataRow row in ds.Tables[0].Select())

  {

  int cellIndex = 0;

  HSSFRow fr = GetRow(sheet1, rowIndex++);

  GetCell(fr, cellIndex++, _style).SetCellValue(i.ToString());

  GetCell(fr, cellIndex++, _style).SetCellValue(row["C_Name"].ToString());

  GetCell(fr, cellIndex++, _style).SetCellValue(DelHTML(row["C_Sex"].ToString()));

  GetCell(fr, cellIndex++, _style).SetCellValue(DelHTML(row["C_WorkUnit"].ToString()));

  GetCell(fr, cellIndex++, _style).SetCellValue(row["C_expert_type"].ToString());

  GetCell(fr, cellIndex++, _style).SetCellValue(row["C_position"].ToString());

  GetCell(fr, cellIndex++, _style).SetCellValue(row["C_title"].ToString());

  GetCell(fr, cellIndex++, _style).SetCellValue(row["C_Tel"].ToString());

  GetCell(fr, cellIndex++, _style).SetCellValue(row["C_BusinessOutlets"].ToString());

  GetCell(fr, cellIndex++, _style).SetCellValue(row["C_BankAccount"].ToString());

  i++;

  }

  sheet1.ForceFormulaRecalculation = true;

  using (FileStream filess = File.OpenWrite(ReportFileName))

  {

  hssfworkbook.Write(filess);

  }

  System.IO.FileInfo filet = new System.IO.FileInfo(ReportFileName);

  Response.Clear();

  Response.Charset = "GB2312";

  Response.ContentEncoding = System.Text.Encoding.UTF8;

  // 添加头信息,为"文件下载/另存为"对话框指定默认文件名

  string name = DateTime.Now + ".xls";

  Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(name));

  // 添加头信息,指定文件大小,让浏览器能够显示下载进度

  Response.AddHeader("Content-Length", filet.Length.ToString());

  // 指定返回的是一个不能被客户端读取的流,必须被下载

  Response.ContentType = "application/ms-excel";

  // 把文件流发送到客户端

  Response.WriteFile(filet.FullName);

  // 停止页面的执行

  Response.End();

  }

  }

  复制代码

  (编辑:雷林鹏 来源:网络)

[.NET开发] NPOI导出的更多相关文章

  1. .net使用NPOI的XSSFWorkbook进行web开发中导出Excel

    之前也使用过NPOI导出excel,这次是因为在导出的excel里新增了几个列,正好超出了255的限制,所以又要改了. 今天主要出了4个问题: 1. Invalid column index (256 ...

  2. .NET NPOI导出Excel详解

    NPOI,顾名思义,就是POI的.NET版本.那POI又是什么呢?POI是一套用Java写成的库,能够帮助开发者在没有安装微软Office的情况下读写Office的文件. 支持的文件格式包括xls, ...

  3. 分享使用NPOI导出Excel树状结构的数据,如部门用户菜单权限

    大家都知道使用NPOI导出Excel格式数据 很简单,网上一搜,到处都有示例代码. 因为工作的关系,经常会有处理各种数据库数据的场景,其中处理Excel 数据导出,以备客户人员确认数据,场景很常见. ...

  4. NPOI导出Excel示例

    摘要:使用开源程序NPOI导出Excel示例.NPOI首页地址:http://npoi.codeplex.com/,NPOI示例博客:http://tonyqus.sinaapp.com/. 示例编写 ...

  5. asp.net Mvc Npoi 导出导入 excel

    因近期项目遇到所以记录一下: 首先导出Excel : 首先引用NPOI包 http://pan.baidu.com/s/1i3Fosux (Action一定要用FileResult) /// < ...

  6. .NET Core使用NPOI导出复杂,美观的Excel详解

    前言: 这段时间一直专注于数据报表的开发,当然涉及到相关报表的开发数据导出肯定是一个不可避免的问题啦.客户要求要导出优雅,美观的Excel文档格式的来展示数据,当时的第一想法就是使用NPOI开源库来做 ...

  7. NPOI导出Excel (C#) 踩坑 之--The maximum column width for an individual cell is 255 charaters

    /******************************************************************* * 版权所有: * 类 名 称:ExcelHelper * 作 ...

  8. 基于NPOI导出和导入Excel

    概述 NPOI,顾名思义,就是POI的.NET版本.NPOI就是用.NET语言编写的一套数据导出Excel的开源项目,支持XML.xls.xlsx.ppt等格式..NET不仅实现Excel导出还可以实 ...

  9. (C#)使用NPOI导出Excel

    在做业务型的软件时,经常需要将某些数据导出,本文介绍了在Winform或Asp.net中使用NPOI(POI 项目的 .NET 版本)来操作Excel文件,而无需安装Office. 首先,需要获取NP ...

随机推荐

  1. python webdriver 测试框架-行为驱动例子

    安装行为驱动模块lettuce(卷心菜)模块 pip install lettuce Successfully installed argparse-1.4.0 colorama-0.3.9 extr ...

  2. linux 判断文件最后更新时间 实现监控日志是否有输出功能

    linux 判断文件最后更新时间 实现监控日志是否有输出功能. 需求:监控log.txt日志文件,超过一分钟没输出内容就认为是停了,则自动启动程序. 用stat 可以看文件的更新时间stat -c % ...

  3. bzoj1658: [Usaco2006 Mar]Water Slides 滑水

    Description It's a hot summer day, and Farmer John is letting Betsy go to the water park where she i ...

  4. Python 自学基础(四)——time模块,random模块,sys模块,os模块,loggin模块,json模块,hashlib模块,configparser模块,pickle模块,正则

    时间模块 import time print(time.time()) # 当前时间戳 # time.sleep(1) # 时间延迟1秒 print(time.clock()) # CPU执行时间 p ...

  5. Educational Codeforces Round 21 Problem D(Codeforces 808D)

    Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into t ...

  6. UVa 10635 Prince and Princess - 动态规划

    讲一下题目大意,就是有两个长度为p + 1和q + 1的序列,求它们的LCS. 如果用O(pq)的算法对于这道题来说还是太慢了.所以要另外想一些方法.注意到序列中的所有元素都不相同,所以两个序列中数对 ...

  7. libcurl开源库在Win32程序中使用下载文件显示进度条实例

    一.配置工程引用libcurl库 #define CURL_STATICLIB #include "curl/curl.h" #ifdef _DEBUG #pragma comme ...

  8. C++11 正则表达式——实例系统(转载)

    一.用正则表达式判断邮箱格式是否正确 1 #include <regex> #include <iostream> #include <string> bool i ...

  9. win7 64位debug解决方法

    1.下载win 64位的DOSBox,如DOSBox0.74: 2.下载win 32 debug.exe,并复制到调用的目录,如d盘根目录d:\ 3.安装DOSBox,并运行:如下图: 4.键入命令: ...

  10. Java之Elasticsearch 增删改查

    <!--ELK --> <dependency> <groupId>org.elasticsearch.client</groupId> <art ...