如题,我现在是这么写的:connection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + file_path + ";" +
                             "Extended Properties=Excel 8.0";
                OleDbDataAdapter excel_data = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connection);
但是打开excel 2007格式的excel会报错,2007格式的connection怎么写?有没有通用的connection,就是2007和2003的都可以连接的?

解决方案 »

  1.   

    string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filePath + ";" + "Extended Properties=\"Excel 8.0;IMEX=1\"";可以用的,记得将变量替换成路径
      

  2.   

    OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=imagedata.xlsx;Extended Properties=Excel 12.0");
    conn.Open();
    07换驱动,不能通用
      

  3.   


    现在用这个只能打开 2007转换成“97-2003”兼容格式的,如果打开.xlsx格式的excel会报错——“外部表不是预期的格式”
      

  4.   


    这样可以了  如果本机没有装excel2007使用这个connection可以打开2003格式的excel么?
      

  5.   

    用NPOI吧,读取很快而且没有垃圾进程,不是单用户。