ASP.NET将数据导出到一个EXCEL文件的多个SHEET中
2016-06-05 22:42
591 查看
一、实现原理
使用用NPOI实现在同一Excel文件中创建多个sheet,只需要在同一个Excel中创建多个sheet即可。
二、实例
文章转载自:ASP.NET将数据导出到一个EXCEL文件的多个SHEET中 http://www.studyofnet.com/news/1264.html
使用用NPOI实现在同一Excel文件中创建多个sheet,只需要在同一个Excel中创建多个sheet即可。
二、实例
private void buttonTest_Click(object sender, EventArgs e) { HSSFWorkbook workBook = new HSSFWorkbook(); //ISheet sheetA = workBook.CreateSheet("sheetA"); //ISheet sheetB = workBook.CreateSheet("sheetB"); createSheet(workBook,"SheetA"); createSheet(workBook,"SheetB"); createSheet(workBook,"SheetC"); string path = Application.StartupPath + @"\\test.xls"; if (File.Exists(path)) { File.Delete(path); } using (FileStream file = new FileStream(path, FileMode.Create)) { workBook.Write(file); //创建Excel文件。 file.Close(); } MessageBox.Show("OK"); } private ISheet createSheet(HSSFWorkbook workBook, string sheetName) { ISheet sheet = workBook.CreateSheet(sheetName); IRow RowHead = sheet.CreateRow(0); for (int iColumnIndex = 0; iColumnIndex < 10; iColumnIndex++) { RowHead.CreateCell(iColumnIndex).SetCellValue(Guid.NewGuid().ToString()); } for (int iRowIndex = 0; iRowIndex < 20; iRowIndex++) { IRow RowBody = sheet.CreateRow(iRowIndex + 1); for (int iColumnIndex = 0; iColumnIndex < 10; iColumnIndex++) { RowBody.CreateCell(iColumnIndex).SetCellValue(DateTime.Now.Millisecond); sheet.AutoSizeColumn(iColumnIndex); } } return sheet; }
文章转载自:ASP.NET将数据导出到一个EXCEL文件的多个SHEET中 http://www.studyofnet.com/news/1264.html
相关文章推荐
- 分享微信开发Html5轻游戏中的几个坑
- 星外ASP.Net的安全设置相关说明
- C#、ASP.NET通用扩展工具类之TypeParse
- 实现ASP.NET无刷新下载并提示下载完成的开发思路
- C#、ASP.NET通用扩展工具类之LogicSugar
- C#、ASP.NET通用工具类IsWhat?(可以判断数字、身份证、数据类型等等)
- 程序中常用的种代码
- ASP.NET、ASP、PHP、JSP之间有什么区别?
- 在ASP.NET 2.0中操作数据之六十六:在TableAdapters中使用现有的存储过程
- ASP.NET页面间的传值的几种方法
- 在ASP.NET 2.0中操作数据之二十四:分页和排序报表数据
- 入侵ASP.net网站的经验附利用代码
- 盘点PHP和ASP.NET的10大对比!
- 在ASP.NET 2.0中操作数据之四十八:对SqlDataSource控件使用开放式并发
- ASP.NET MVC4入门教程(四):添加一个模型
- 在ASP.NET 2.0中操作数据之二十三:基于用户对修改数据进行限制
- 在ASP.NET 2.0中操作数据之七十三:用Managed Code创建存储过程和用户自定义函数(上部分)
- ASP.NET MVC4入门教程(五):从控制器访问数据模型
- 在ASP.NET 2.0中操作数据之六十七:在TableAdapters中使用JOINs
- ASP.NET中 CheckBox复选框控件的使用