目前有一个EXCL文件需要读取里面的内容到数据库的指定表,可是不能使用Microsoft.Jet.OLEDB.4.0,请教大家怎么做,最好附代码!

解决方案 »

  1.   

    http://mysnz.blog.163.com/blog/static/6030954020091262113395/第一种方法
      

  2.   

    1.把Excel另存为2003及其以前的版本,用"Provider=Microsoft.Jet.Oledb.4.0;Data Source="绝对路径";Extended Properties=Excel 8.0;"
    2.如果是2007的版本,用Provider=Microsoft.ACE.OLEDB.12.0;Data Source="路径";
      

  3.   

    1.把Excel另存为2003及其以前的版本,用"Provider=Microsoft.Jet.Oledb.4.0;Data Source="绝对路径";Extended Properties=Excel 8.0;"
    2.如果是2007的版本,用Provider=Microsoft.ACE.OLEDB.12.0;Data Source="路径";》》
    不能用Microsoft.Jet.Oledb.4.0
      

  4.   

    http://mysnz.blog.163.com/blog/static/6030954020091262113395/第一种方法》》打不开
      

  5.   

          oExcel = new Excel.Application();                oExcel.Visible = false;
                    oExcel.DisplayAlerts = false;                oBooks = oExcel.Workbooks;                oBooks.Open(Excel_Path + File_Name, oMissing, oMissing,
                        oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
                        oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
                    oBook = oBooks.get_Item(1);
                    oSheets = oBook.Worksheets;
                    oSheet = (Excel.Worksheet)oSheets.get_Item(1);
                    oCells = oSheet.Cells;
     DataTable dt = new DataTable();
                int iRow = 1;            while (((Excel.Range)oCells.Cells[iRow, 1]).Text.ToString().Trim() != string.Empty)
                {
                    int iCol = 1;
                    if (iRow == 1)
                    {
                        while (((Excel.Range)oCells.Cells[iRow, iCol]).Text.ToString().Trim() != string.Empty)
                        {
                            dt.Columns.Add(((Excel.Range)oCells.Cells[iRow, iCol]).Text.ToString().Trim());
                            iCol++;
                        }
                    }
                    else
                    {
                        DataRow dr = dt.NewRow();
                        //while (((Excel.Range)oCells.Cells[iRow, iCol]).Text.ToString().Trim() != string.Empty)
                        //{
                        for (int i = 1;i<= dt.Columns.Count; i++)
                        {                        dr[i - 1] = ((Excel.Range)oCells.Cells[iRow, i]).Text.ToString().Trim();
                            iCol++;
                        }
                        //}
                        dt.Rows.Add(dr);
                    }
                    iRow++;
                }