惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
Y
Y Combinator Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
博客园_首页
小众软件
小众软件
I
InfoQ
J
Java Code Geeks
月光博客
月光博客
S
Secure Thoughts
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Stack Overflow Blog
Stack Overflow Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
N
News and Events Feed by Topic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
T
Threat Research - Cisco Blogs
A
About on SuperTechFans
H
Help Net Security
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Latest news
Latest news
G
GRAHAM CLULEY
IT之家
IT之家
C
Cisco Blogs
Last Week in AI
Last Week in AI
Engineering at Meta
Engineering at Meta
L
LangChain Blog
The Register - Security
The Register - Security
SecWiki News
SecWiki News
M
MIT News - Artificial intelligence
NISL@THU
NISL@THU
T
Tenable Blog
博客园 - Franky
美团技术团队
I
Intezer
U
Unit 42
雷峰网
雷峰网
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
SegmentFault 最新的问题
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - 独孤雁

在win2008中安装vs2005 【转】NPOI 单元格级别应用 [转]google hosts 2015 [转] C#反射设置属性值和获取属性值 [转]Visual Studio技巧之打造拥有自己标识的代码模板 【转】mysql如何跟踪执行的sql语句 [转]VS2005/2008过期之后简单实用的升级方法 【转】在web 项目使用了ReportViewer时出错 .NET中TextBox控件设置ReadOnly=true后台取不到值的解决方法 window.location 对象所包含的属性 【原】提交按钮被隐藏,回车一样提交表单 【转】Eclipse安装SVN插件 [转]listview学习 安卓App程序访问网络 需要配置权限(java.net.SocketException: Permission denied) 【转】Android模拟器怎么配置网络连通 【转】Adobe Dreamweaver CS5序列号 【转】HTML特殊符号对照表 【转】ScriptX打印问题 Android SDK Manager无法更新的解决
使用NPOI导出excel
独孤雁 · 2014-09-24 · via 博客园 - 独孤雁

NPOI下载地址http://npoi.codeplex.com/releases

从项目中引用NPOI.bll和NPOI.OOXML.bll

引用命名控件

using NPOI.HSSF.UserModel;
using NPOI.XSSF.UserModel;
using NPOI.SS.UserModel;

using System.IO;

在页面(*.aspx)中使用

protected void Button1_Click(object sender, EventArgs e)
        {
            enumCj_State cjState = enumCj_State.待审核;

            tbCj_Sale_BaseInfo[] objList = cjManager.search_cj_sale_tongji(null, null, (int)cjState, -1, string.Empty);

            HSSFWorkbook workbook = new HSSFWorkbook();
            ISheet sheet = workbook.CreateSheet("销售当日台账");
            IRow headrow = sheet.CreateRow(0);//编写标题列
            headrow.CreateCell(0, CellType.String).SetCellValue("签约店");
            headrow.CreateCell(1, CellType.String).SetCellValue("业务编号");

            int intRolNum = 0;
            foreach (tbCj_Sale_BaseInfo objcj in objList)
            {
                IRow row = sheet.CreateRow(intRolNum + 1);
                //row.CreateCell(0, CellType.String).SetCellValue(((DateTime)objcj.CJ_DATE).ToShortDateString());
                row.CreateCell(1, CellType.String).SetCellValue(objcj.QY_DEPTNAME);
                row.CreateCell(2, CellType.String).SetCellValue(objcj.FK_FYCode);
                
                    intRolNum ++;
            }

            MemoryStream ms = new MemoryStream();
            workbook.Write(ms);

            // 設定強制下載標頭
            Response.AddHeader("Content-Disposition", string.Format("attachment; filename=Download.xls"));
            // 輸出檔案
            Response.BinaryWrite(ms.ToArray());
            ms.Close();
            ms.Dispose();
            Response.End();
        }

在一般程序(*.ashx)中使用

case "excel":
                    {
                        context.Response.Clear();
                        context.Response.ClearContent();
                        context.Response.ClearHeaders();
                       

                        context.Response.ContentType = "application/x-excel";
                        string fileName = HttpUtility.UrlEncode("动态数据库.xls");
                        context.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet();
                        HSSFRow row = (HSSFRow)sheet.CreateRow(0);

                      

                        row.CreateCell(1, CellType.String).SetCellValue("Hello excel");

                  

                        MemoryStream ms = new MemoryStream();
                        workbook.Write(ms);

                        // 設定強制下載標頭

                        context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=Download.xls"));
                        // 輸出檔案
                        context.Response.BinaryWrite(ms.ToArray());
                        ms.Close();
                        ms.Dispose();
                        context.Response.End();

                        break;
                    }