导入excle到DataTable
2013-06-06 22:32
127 查看
public static System.Data.DataTable InputExcel(string Path, ref string exceptionMsg) { System.Data.DataTable dt = new System.Data.DataTable(); try { string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;"; using (OleDbConnection conn = new OleDbConnection(strConn)) { conn.Open(); System.Data.DataTable sheetDt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string[] sheet = new string[sheetDt.Rows.Count]; for (int i = 0; i < sheetDt.Rows.Count; i++) { sheet[i] = sheetDt.Rows[i]["TABLE_NAME"].ToString(); } string strExcel = string.Format("select * from [{0}]", sheet[0]); OleDbDataAdapter myCommand = new OleDbDataAdapter(strExcel, strConn); dt = new System.Data.DataTable(); myCommand.Fill(dt); conn.Close(); } } catch (Exception ex) { exceptionMsg = ex.Message; } return dt; }
以上转自网上
相关文章推荐
- Excle导入导出功能
- 将Excle中的数据批量导入数据库
- 导出Excel 把一个dataset的多个datatable导入到一个excel的多个sheet中
- 使用JXL对EXCLE的导入导出
- Java +EasyUI+SpringMvc实现Excle导入导出(下)
- 与DataTable有关的数据导入导出
- asp.net(c#) DataTable 快速导入数据库
- SpringMVC 实现POI读取Excle文件中数据导入数据库(上传)、导出数据库中数据到Excle文件中(下载)
- 导入Excle数据至数据库 “外部表不是预期的格式”错误信息
- SPlist按PID层级顺序导入datatable
- Excel 导入到Datatable 中,再使用常规方法写入数据库
- excle数据导入mysql数据库应主意的问题
- Excle导入到MSSql
- DataTable导入导出Excel
- 评教系统优化之使用事务批量导入DataTable
- 黑马程序员_筛选DataTable中的数据,批量导入到数据库中
- Excel导入其他Excle文件中的某一单元格内容
- 使用NPOI导入导出Excel(xls/xlsx)数据到DataTable中
- 一个DataTable的数据如何导入另外一个DataTable中!!
- SqlBulkCopy方法批量导入DataTable表中的数据