paulyoder / LinqToExcel

Use LINQ to retrieve data from spreadsheets and csv files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception: External table is not in the expected format.

arame opened this issue · comments

I have an Excel 2013 spreadsheet in which I load Sheet3, column 0 into the database.

var rows = GetExcelDataRows(file);
foreach (var row in rows)
{ // ... load data }

    private static IEnumerable<Row> GetExcelDataRows(HttpPostedFileBase file)
    {
        var excelFilePath = file.FileName;
        var excel = new ExcelQueryFactory(excelFilePath);
        var rows = excel.Worksheet("Sheet3").ToList();
        return rows;
    }

This code works! Except when I edit my spreadsheet in Excel 2013, I get this exception:
System.Data.OleDb.OleDbException: External table is not in the expected format. It is triggered on this line; var rows = excel.Worksheet("Sheet3").ToList();

Why is this happening, how do I fix this?

I have faced the same issue (i was using Asp.Net MVC).
I resolved it by

  1. Installing Access database engine 2010
  2. Installing Access database engine 2007
  3. Save the file to your local directory and then read from that location.
    public void UploadRecords(HttpPostedFileBase file, int programId)
    {
    file.SaveAs(@"\PathToFolder" + fileNamewithExtension);
    using (var excelFile = new ExcelQueryFactory(@"\PathToFolder" + fileNamewithExtension))
    {
    var listOfModel = from testModel in excelFile.Worksheet("SheetName")
    select testModel;
    }
    }
    4.Delete the file which was saved in step 3

Hi palakshamb, I'm facing this same issue. I downloaded the library into my MVC4 application. Then, I installed both Access database engine 2010 and 2007. I have a .xlsx file saved already on my desktop which I'm reading. Is there anything else i need to do to fix this error ?

Exception: External table is not in the expected format

This exception occurred because LinqToExcel not able to read your excel file.
That can cause by some reasons

  • Extensions might be changed externally. (Without excel application)
  • Your excel file can be broken or not in a proper format

I have faced to this same situation. What I have done is,

Open the file from excel and again Save As it with a different name with same extension.

It worked for me.