public Form1()
        {
            InitializeComponent();            button1.Name = "btnGetXls";
            button1.Click += new EventHandler(btnGetXls_Click);
        }        private void btnGetXls_Click(object send, EventArgs e)
        {
            string PathName = Application.StartupPath + "\\JetEazyTilt.xls";            ExcelToDataGridView(PathName, this.dgvTilt);
        }        public void ExcelToDataGridView(string filePath, DataGridView dgv)
        {
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties ='Excel 14.0;HDR=NO;IMEX=1'";
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            OleDbDataAdapter myCommand = null;
            DataSet ds = null;
            strExcel = "select * from [sheet1$]";
            myCommand = new OleDbDataAdapter(strExcel, strConn);
            ds = new DataSet();
            myCommand.Fill(ds, "table1");            DataTable tb = new DataTable();
            foreach (DataGridViewColumn dgvc in dgv.Columns)
            {
                if (dgvc.Visible && dgvc.CellType != typeof(DataGridViewCheckBoxCell))
                {
                    DataColumn dc = new DataColumn();
                    dc.ColumnName = dgvc.DataPropertyName;
                    tb.Columns.Add(dc);
                }
            }            foreach (DataRow excelRow in ds.Tables[0].Rows)
            {
                int i = 0;
                DataRow dr = tb.NewRow();
                foreach (DataColumn dc in tb.Columns)
                {
                    dr[dc] = excelRow[i];
                    i++;
                }
                tb.Rows.Add(dr);
            }
            dgv.DataSource = tb;
        }conn.Open();的时候报错了!就是找不到可安装的 ISAM  在线等!!急死人了

解决方案 »

  1.   

    Excel 14.0改为Excel 8.0试试
      

  2.   

    试过了~~还是不行!!我的是office2010的~组件是excel 14.0的!怎么办?
      

  3.   

    add the component into the project
      

  4.   

     string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + file + ";Extended Properties=\"Excel 12.0 Xml;HDR=NO\"";
      

  5.   

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+filePath+";Extended Properties=Excel 8.0这个又是哪里错呢?出错的提示和楼主的一样呀