Click here to Skip to main content
15,910,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm trying to insert an image in excel through coding.
The following code inserts a picture in to the sheet. Its fine. But my images are not in filesystem. I'm retrieving them from database. Without saving the images into filesystem is there a way to directly add them in to excel?

VB
'ws is worksheet object
ws.Shapes.AddPicture("myimage.jpg", MsoTriState.msoFalse, MsoTriState.msoTrue, 1, 1, 2, 3)


Language : vb.net
Excel : Excel.dll ver 11.0 ( Office 2003)

Kindly suggest.
Posted
Updated 28-Jul-13 23:39pm
v2
Comments
Maciej Los 5-May-12 6:13am    
What kind of database? Type of field (BLOB)?
thams 5-May-12 6:26am    
yes its blob.
I'm using oracle.
I've retrieved the blob data and I can present it in memory stream or even in image/ bitmap object (of .net).

Take a look here[^] An example is in C#, but i think it's not problem to understand it or translate[^] it.

If you can read BLOB field into a memory or image bitmap, you're home! ;)
Option 1
Save this data into temporary folder (C:\Temp), add picture to the worksheet with option SaveWithDocument=True and delete picture from temporary folder.

Option 2
When a picture is in memory, you can pate it content into Worksheet ;)
VB
wsh.Range("A1").Select
wsh.Paste()


More at: AddPicture Method[^]
 
Share this answer
 
v2
Comments
thams 5-May-12 7:17am    
Hi losmac,
Thanks a lot.
I've already finished the task as you said.
Even in my question I've clearly stated that "Without saving the images into filesystem".

Op 2
I meant that I've image as memory stream ie System.IO.MemoryStream, not in clipboard memory.
Is there any other short way?
Maciej Los 5-May-12 16:11pm    
Ok, i'll try to show you an example for opt. 2. But, please, be patient.
 
Share this answer
 
v2
Comments
thams 5-May-12 6:06am    
Thanks for your response.
But pls understand my que clearly. I'm not asking help to add images that are saved in hard disk. I'm asking for images from streams.

PS: I've also searched in google.
Maciej Los 5-May-12 6:09am    
My vote: 1! Reason: This is not good answer, becouse the following example shows how to add picture from existing file. The OP wrote: "But my images are not in filesystem. I'm retrieving them from database.". Show good example and i'll re-vote.

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