C# Winform读取Excel
来源:互联网 发布:mac进不了安全模式 编辑:程序博客网 时间:2024/06/06 16:31
在 WinForm中打开Excel
添加 openFileDialog(openFileDialogSource) 和 toolStrip 和ComboBox(ctlPath) 控件
//代码:DataTable dTable;// 打开 private void buttonOpen_Click(object sender, EventArgs e) { if (openFileDialogSource.ShowDialog()==DialogResult.OK) { ctlPath.Text = openFileDialogSource.FileName; ExceltoDataSet(ctlPath.Text); } }//打开方法 public DataTable ExceltoDataSet(string path) { string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1';"; OleDbConnection conn = new OleDbConnection(strConn); conn.Open(); System.Data.DataTable schemaTable = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null); string tableName = schemaTable.Rows[0][2].ToString().Trim(); string strExcel = ""; OleDbDataAdapter myCommand = null; DataSet ds = null; strExcel = "Select * From [" + tableName + "]"; myCommand = new OleDbDataAdapter(strExcel, strConn); ds = new DataSet(); myCommand.Fill(ds, tableName); System.Data.DataTable dt = ds.Tables[0]; dTable = dt; return dt; } //显示数据private void tsbRefresh_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(ctlPath.Text)) { ctlPath.Focus(); return; } try { for (int i = 7; i >= 0; i--) { dTable.Rows.Remove(dTable.Rows[i]); } gridSource.DataSource = dTable;// gridSource :( DataGridView) } catch (Exception) { throw; } }
- C# Winform读取Excel
- WinForm读取Excel文件
- WinForm读取Excel文件
- WinForm读取Excel文件
- winForm c#导出Excel
- C# WinForm导出Excel
- C# winform 开发之Excel操作(二)------读取Excel表格
- C# winform 开发之Excel操作(二)------读取Excel表格 (续)
- C# winform 开发之Excel操作(二)------读取Excel表格
- c# winform操作excel,选择最合适的组件来读取XLS
- C# WinForm开发系列 - Excel
- C# WinForm创建Excel文件
- C#读取Excel,导出Excel
- C#读取Excel,导出Excel
- C#读取excel表
- C#读取Excel数据
- C#读取Excel数据
- C#读取Excel数据
- 《微机原理及接口技术》第04章在线测试
- P2P在NAT和防火墙上的穿透
- C#常用操作
- PHP+ACCESS 实例
- JAVA中toString方法的作用
- C# Winform读取Excel
- 程序中如何获取Android的Root权限
- P2P应用中的NAT穿透原理(简析版)
- “七十二变”进制函数
- C#冒泡排序
- linux
- Android 禁止黑屏进入省电模式
- android源代码,镜像站下载
- ecshop 2.7.3修改admin密码