Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an excel file where it contains an image in the header, I don't care about that image even if it has to be removed. 

I get the following error message while making the connection to the file which contains the image.

    conn.Open();

**External table is not in the expected format**

Whereas if I remove the image from the same excel, everything works fine.

I am looking for a solution to the same, if solution suggests removing the image from excel using C# then it should not be referring to any third party DLL, neither I can have Microsoft office on the server.


Is there any possibility to remove image from excel without OleDb, without office being installed or without using any third party dll ?

Thanks in advance.


What I have tried:

I have tried using third party libraries which are rejected by client, MS office will not be provided on the server and OleDb cannot make a connection to the file which contain Shapes.
Posted
Updated 25-Jun-18 22:07pm
Comments
Richard MacCutchan 25-Jun-18 6:28am    
I just tried to open an XLSX file with an image in the sheet and it works fine. You need to provide more details.

1 solution

Just ignore headers. All you need to do is to change connection string from:
C#
strig sConn= string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}='Excel 12.0 Xml;HDR=YES;';", sFullFileName);

to:
C#
strig sConn= string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0 Xml;HDR=NO;';", sFullFileName);


For further details, please see: Excel connection strings - ConnectionStrings.com[^]
 
Share this answer
 
Comments
Richard MacCutchan 26-Jun-18 4:26am    
I had "HDR=YES" in my code and it loaded fine, and just ignored the image.
Maciej Los 26-Jun-18 4:32am    
Seems, it depends on image... ;)
Richard MacCutchan 26-Jun-18 4:35am    
As is so often the case, not enough information.
Maciej Los 26-Jun-18 4:37am    
Oh, yeah!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900