Excel “External table is not in the expected format.”

后端 未结 24 1543
执念已碎
执念已碎 2020-11-22 05:13

I\'m trying to read an Excel (xlsx) file using the code shown below. I get an \"External table is not in the expected format.\" error unless I have the file already open in

相关标签:
24条回答
  • 2020-11-22 05:32

    If the file is read-only, just remove it and it should work again.

    0 讨论(0)
  • 2020-11-22 05:32

    My scope consists of template download and verifies the template when it's filled with data So,

    1) Download a template (.xlsx) file with the header row. the file is generated using openxml and it's working perfectly.

    2) Upload the same file without any change from it's downloaded state. This will cause a connection error and fails (OLEDB connection is using for reading the excel sheet).

    Here if the data is filled the program works as expected.

    Anybody having an idea the issue is connected with the file we are creating it's in xml format if we open it and just save convert it in to excel format and it works well.

    Any idea to download the excel with the preferred file type?

    0 讨论(0)
  • 2020-11-22 05:34

    Instead of OleDb, you could use the Excel Interop and open the worksheet as read-only.

    https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.workbooks.open(v=office.15).aspx

    0 讨论(0)
  • 2020-11-22 05:35

    I had this same issue(Using the ACE.OLEDB) and what resolved it for me was this link:

    http://support.microsoft.com/kb/2459087

    The gist of it is that installing multiple office versions and various office sdk's, assemblies, etc. had led to the ACEOleDB.dll reference in the registry pointing to the OFFICE12 folder instead of OFFICE14 in

    C:\Program Files\Common Files\Microsoft Shared\OFFICE14\ACEOLEDB.DLL

    From the link:

    Alternatively, you can modify the registry key changing the dll path to match that of your Access version.

    Access 2007 should use OFFICE12, Access 2010 - OFFICE14 and Access 2013 - OFFICE15

    (OS: 64bit Office: 64bit) or (OS: 32bit Office: 32bit)

    Key: HKCR\CLSID{3BE786A0-0366-4F5C-9434-25CF162E475E}\InprocServer32\

    Value Name: (Default)

    Value Data: C:\Program Files\Common Files\Microsoft Shared\OFFICE14\ACEOLEDB.DLL

    (OS: 64bit Office: 32bit)

    Key: HKCR\Wow6432Node\CLSID{3BE786A0-0366-4F5C-9434-25CF162E475E}\InprocServer32\

    Value Name: (Default)

    Value Data: C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE14\ACEOLEDB.DLL

    0 讨论(0)
  • 2020-11-22 05:35

    This can occur when the workbook is password-protected. There are some workarounds to remove this protection but most of the examples you'll find online are outdated. Either way, the simple solution is to unprotect the workbook manually, otherwise use something like OpenXML to remove the protection programmatically.

    0 讨论(0)
  • 2020-11-22 05:35

    Working with some older code and came across this same generic exception. Very hard to track down the issue, so I thought I'd add here in case it helps someone else.

    In my case, there was code elsewhere in the project that was opening a StreamReader on the Excel file before the OleDbConnection tried to Open the file (this was done in a base class).

    So basically I just needed to call Close() on the StreamReader object first, then I could open the OleDb Connection successfully. It had nothing to do with the Excel file itself, or with the OleDbConnection string (which is naturally where I was looking at first).

    0 讨论(0)
提交回复
热议问题