Excel “External table is not in the expected format.”

后端 未结 24 1600
执念已碎
执念已碎 2020-11-22 05:13

I\'m trying to read an Excel (xlsx) file using the code shown below. I get an \"External table is not in the expected format.\" error unless I have the file already open in

24条回答
  •  失恋的感觉
    2020-11-22 05:41

    ACE has Superceded JET

    Ace Supports all Previous versions of Office

    This Code works well!

            OleDbConnection MyConnection;
            DataSet DtSet;
            OleDbDataAdapter MyCommand;
            
            MyConnection = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\\Book.xlsx;Extended Properties=Excel 12.0;");
            MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
            DtSet = new System.Data.DataSet();
            
            MyCommand.Fill(DtSet);
            dataGridView1.DataSource = DtSet.Tables[0];
            MyConnection.Close();
    

提交回复
热议问题