5

Look at this post: Excel "External table is not in the expected format."

I have the same problem depicted in that post but I'm using LinqtoExcel to read the file instead of plain queries.

What would be the LinqToExcel equivalent for setting the connection string as the answer to that post suggests?

Here is the code I'm using:

var excelOM = new ExcelQueryFactory(pPathArchivoOM);
var despachosClient = from c in excelOM.Worksheet<RegistroDespachoOM>("Tabla_1")
                         where c.DESTINAT.Contains("SOMETEXT")
                         select c;
//Identificar los despachos asociados a números de documento sin datos aún.
foreach (RegistroDespachoOM despacho in despachosClient)
{ ...

And my problem is: "External table is not in the expected format" in the foreach start.

EDIT (my problem is solved but the question remains unanswered): I'm using EPPlus instead of LinqToExcel for this task and all is working OK now.

Community
  • 1
  • 1
daniloquio
  • 3,822
  • 2
  • 36
  • 56
  • LinqToExcel works for excel 2007 files as well. You just need to use the Ace database engine, which is explained in the answer below. – Paul Apr 01 '13 at 11:18

1 Answers1

5

You will need to use the ACE database engine instead of the JET database engine.

You can do this with LinqToExcel by setting the DatabaseEngine property. Here's an example

var excelOM = new ExcelQueryFactory(pPathArchivoOM);
excelOM.DatabaseEngine = DatabaseEngine.Ace;
Paul
  • 18,349
  • 7
  • 49
  • 56
  • 1
    Thanks! I didn't find any property like DatabaseEngine because I was using LinqToExcel 1.0. I updated to LinqToExcel 1.6 and now that property is there; setting it allowed me to read the problematic file with LinqToSql. I will keep using EPPlus though because it is more object oriented. LinqToExcel will is my option to pure excel 97/2003 files. – daniloquio Jun 13 '12 at 20:05
  • @daniloquio LinqToExcel can still read Excel 2007 files. You just need to use the Ace database engine. – Paul Apr 01 '13 at 11:18
  • on 64bit change the extension to xls or just remove it. Without that - same error. - - - - From documentation: Sets the database engine to use (Spreadsheets ending in xlsx, xlsm, and xlsb must use the Ace database engine) (If running 64 bit this defaults to ACE (JET doesn't work anyway), if running 32 bit this detaults to JET) – Artiom Jan 17 '14 at 20:02