NPOI在DataGridView中展示excel中的数据
来源:互联网 发布:卖茶淘宝店铺简介 编辑:程序博客网 时间:2024/05/21 08:54
HSSFWorkbook hssfworkbook; DataSet ds = new DataSet(); /// <summary> /// 初始化一个工作薄 /// </summary> /// <param name="path">工作薄的路径</param> void InitializeWorkbook(string path) { using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read)) { hssfworkbook = new HSSFWorkbook(file); } } void ConvertToDataTable() { ISheet sheet = hssfworkbook.GetSheetAt(0); System.Collections.IEnumerator rows = sheet.GetRowEnumerator(); DataTable dt = new DataTable(); for (int i = 0; i < sheet.GetRow(0).LastCellNum; i++) { dt.Columns.Add(Convert.ToChar(((int)'A') + i).ToString()); } while (rows.MoveNext()) { IRow row = (HSSFRow)rows.Current; DataRow dr = dt.NewRow(); for (int j = 0; j < row.LastCellNum; j++) { ICell cell = row.GetCell(j); if (cell == null) { dr[j] = null; } else { dr[j] = cell; } } dt.Rows.Add(dr); } ds.Tables.Add(dt); } private void btnReader_Click(object sender, EventArgs e) { InitializeWorkbook("test.xls"); ConvertToDataTable(); dgViewTest.DataSource = ds.Tables[0]; }
附:
使用NPOI将DataGridView的数据导出EXCEL
0 0
- NPOI在DataGridView中展示excel中的数据
- c#中使用npoi将datagridview中的全部数据导出到excel中去
- 在VS2005中,将DataGridView中的数据导入Excel文件
- 将DataGridView中的数据导入Excel中
- 将excel中的数据导入datagridview中
- datagridview中的数据导入到excel中
- 使用NPOI将DataTable中的数据导入到Excel中
- 在VS2005中,将DataGridView中的数据导入到Excel文件中
- 使用NPOI将DataGridView的数据导出EXCEL
- 将DataGridView中的数据导入Excel中,并显示Excel
- NPOI读取EXCEL到datagridview
- NPOI在.net中的操作Excel
- C#中将DataGridView中查询出来的数据使用DataTable导出为Excel表格(通过NPOI)
- DataGridView中的数据导入Excel
- NPOI操作2003 EXCEL 将Excel中的数据读入table中
- 把DatagridView中的数据导入到Excel中
- c#将datagridview中的数据导入到Excel中(winForm)
- C#实现将DataGridView中的数据导入到Excel中
- J2EE13大规范
- oracle SQL *Plus常用命令
- 第六周实践项目2-建立链栈算法库
- Validations in MVC
- 第3周项目2 建设“顺序表”算法库
- NPOI在DataGridView中展示excel中的数据
- jQuery Mobile基础10----jQuery Mobile Widgets(2)-selectmenu(下拉框
- 第六周项目2-建立链栈算法库
- mv指令
- 驱动预安装成功
- ASM磁盘测试
- 数据结构实践——数制转换
- 银联基于OpenStack的金融私有云建设实践
- NoSQL非关系型数据库