乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > -asp.net excel批量导入,asp读取excel数据

-asp.net excel批量导入,asp读取excel数据

作者:乔山办公网日期:

返回目录:excel表格制作







用OLEDB进行Excel文件数据读取并返DataSet数据集其几点需要注意:

1.连接字符串参数IMEX 值:
0 is Export mode
1 is Import mode
2 is Linked mode (full update capabilities)
IMEX3值:IMEX=2 EXCEL文档同含字符型数字型比第C列3值2数值型 1231字符型 ABC导入
页面报错库显示数值型123字符型ABC则呈现空值IMEX=1述情况发库确呈e799bee5baa6e79fa5e98193e4b893e5b19e336现 123  ABC.
2.参数HDR值:
HDR=Yes代表第行标题做数据使用 用HDR=NO则表示第行标题做数据使用系统默认YES
3.参数Excel 8.0
于Excel 97版本都用Excel 8.0

 #region 获取excel dataset ,即名excel_ds
               string excelFilePath = openFileDialog1.FileName;//弹文件选取窗口获取EXCEL文件路径
               string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelFilePath + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";
               OleDbConnection Oleconn = new OleDbConnection(strConn);
               string strExcel = "";
               OleDbDataAdapter excelCommand = null;
               DataSet excel_ds = new DataSet();
               strExcel = "select * from [sheet1$]";
               try
               {
                   Oleconn.Open();
                   excelCommand = new OleDbDataAdapter(strExcel,Oleconn);
                   excelCommand.Fill(excel_ds,"exdtSource");//dataset
               }
               catch (System.Exception ex)
               {
                   MessageBox.Show("导入错:" + ex, "错误信息");
               }
               finally
               {
                   Oleconn.Close();
                   Oleconn.Dispose();
               }
               #endregion

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网