Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 470
daniloquio Avatar asked Jun 04 '12 15:06

daniloquio


1 Answers

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;
like image 146
Paul Avatar answered Oct 12 '22 09:10

Paul