首页 新闻 会员 周边 捐助

关于读取excel的问题

0
悬赏园豆:20 [待解决问题]

代码如下:问题是 无法导入int型的数据,速求!!!!!!!!!!先谢谢各位了!!

try
            {
                //通过Jet OLEDB
                string Path = this.txtFilePath.Text;
                DataSet ds = null;
                string strall = null;
                string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
                OleDbConnection conn = new OleDbConnection(strConn);
                conn.Open();//打开connection对象
                string strExcel = "";
                OleDbDataAdapter myCommand = null;//配置OLEDB适配器

                //strExcel = "select * from [Sheet1$]";
                if (this.cbxAccount.Checked == true)
                    strExcel = "select  帐号 from [Sheet1$]";
                else if (this.cbxNick.Checked == true)
                    strExcel = "select  昵称 from [Sheet1$]";


                myCommand = new OleDbDataAdapter(strExcel, strConn);//COMMAND对象
                ds = new DataSet();
                myCommand.Fill(ds);//填充DataSet

                paramList.Clear();

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i].ItemArray[0].ToString().Trim() != "")
                    {
                        //新建DataRow行
                        paramList.Add(ds.Tables[0].Rows[i].ItemArray[0].ToString());
                    }

                }

                if (paramList.Count == 0)
                {
                    MessageBox.Show("文件错误!");
                    return;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

墨羽的主页 墨羽 | 初学一级 | 园豆:160
提问于:2011-06-17 11:38
< >
分享
所有回答(1)
0

我建议楼主可以学习下NPOI,对Excel的操作特别的简单,如果有需要我可以给你发个Demo,就是关于你现在做的这个

王元勋 | 园豆:413 (菜鸟二级) | 2011-06-17 13:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册