Trouble with opening excel 2007 xlsx files RRS feed

  • Question

  • The problem is that everytime i open an xlsx file it comes up with the error "The External table is not in correct format".

    I have worked out that it is the currentfile string, it doesnt appear to like it(comes from an openfiledialog). I entered the address of the file in the connection string manually and it worked. I have also compared the connection strings, the one used when i open the file myself, and the one when i entered the address into the code... they looked exactly the same Tongue Tied, but the openfiledialog one doesnt work. What futher confuses me is when I open a xls file it works perfectly, but the whole idea was so that it could be used with xlsx files as well. I have searched and searched and i cant find any answers, i have also spent ages trying different things to get it working. Any help you can give me?

    Code Snippet

    OleDbConnection xlsConnect = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + currentFile + @";Extended Properties=""Excel 12.0 Xml;HDR=YES""");


    OleDbDataAdapter myCommand = new OleDbDataAdapter(" SELECT * FROM [Sheet$]", xlsConnect);


    this.dataGridView1.DataSource = dataSet.Tables[0].DefaultView;

    Tuesday, August 26, 2008 8:48 AM

All replies

  • Can you post the connection string that you get after concatenation is done? You can print it from your code using next kind of code


    Debug.Print (xlsConnect.ConnectionString);


    Friday, August 29, 2008 9:45 AM