Search code examples
c#linq-to-excel

Reading xlsx saved as xls with LinqToExcel


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.


Solution

  • 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;