Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello right now I have a program that uses the oledpadapter to retrieve information from an excel file and displays the data into a datagridview. I'm hoping to find a way to retrieve a bitmap image from my excel file and display it into my datagridview. Is there an easy way of doing this? I greatly appreciate any help or suggestions anyone can give!
Posted
Comments
Appokea 19-Feb-16 4:38am    
As mentioned below this task will require some alternative approach from OLEDB.
What I did in the past is I used a VB.NET library for excel processing, I would iterate through all the images in my spreadsheet file like the following:

Dim workbook = ExcelFile.Load("Sample.xlsx")

For Each worksheet In workbook.Worksheets
For Each picture In worksheet.Pictures
Dim picPosition As ExcelDrawingPosition = picture.Position
Dim picStream As MemoryStream = picture.PictureStream
' ...
Next
Next

Also I should point out that you can actually directly export your excel file into a DataGridView control with VB.NET code. Beside excel cells data this will also export hyperlinks, formattings, images, etc.

In my opinion it's not possible because of the way in which Excel stores images in its files. Have a look here: http://stackoverflow.com/questions/2632715/retrieve-pictures-from-excel-file-using-oledb[^]
 
Share this answer
 
Not this way, since the ole interface is giving you access to the cells only. The images are not in the cells, they are separate objects shown above the actual Excel grid. But you can use Excel interop[^] or third party libraries that can read excel files without excel being installed. But with this approach, you need to parse the sheet cell by cell - object by object, you won't be able to see it as a table. If you are using Excel 2007 or above, there is a "Table" concept, you could also tale advantage of (start with this VBA intro: http://www.jkp-ads.com/Articles/Excel2007TablesVBA.asp[^], but you will find it's VB.NET equivalent also).
 
Share this answer
 
Comments
Maciej Los 6-Aug-13 17:15pm    
Zoltan, i really do appreciate your answer, but you need to know that fetching images from Excel using interop is a torture, especially when picture is stored in Shape object (Excel 97-2003)...
A5 - for alternative way to fetch images from Excel (even if it's not the best and the simplest way).
Zoltán Zörgő 7-Aug-13 8:25am    
Hi, well, I am using interop often, so I know how it works. But I can't call it a torture. You can use the TopLeft and BottomRight properties to get shapes position. But you can use third party components (like this: http://epplus.codeplex.com/) that are able to read (and write) excel files without interop - pictures too. This one is for 2007 and up, but you can find some, that can do the same with the old format too.
Maciej Los 7-Aug-13 8:38am    
Maybe my words were to strong in this context, but... how do you recognize which picture belongs to every single record? It's a real torture ;)
Cheers!
Maciej
Zoltán Zörgő 7-Aug-13 8:40am    
Well, if the table is properly formatted, the images should fit into their rows. If they don't - well, than it is really a torture - but it would be for a human player too, not only for a code.
Maciej Los 7-Aug-13 9:01am    
Agree ;)

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