0

Is it possible to display an image directly from variable? I made a program that receives data from sql server and generates tables in excel. However sql could also have binary values for images and so on... which I would like to display in excel cells. But loadpicture, addpicture don't support this... I would like to avoid saving them into temporary files or avoid using external programs and display directly from memory while afterwards keeping the images in excel. Is this possible?

Dam Gal
  • 135
  • 2
  • 11

2 Answers2

0

Ok tricky :) Shape images can comes from file or from the web. So how about to implement a tiny webserver via vba which serves those images. VBA Webserver for Excel or homebrewed web server vba (If you get websocks running ) BTW: to implement a webserver is rather trivial. In your case he just has to deliver the images - which is done by a base64 encoded string with a few header lines. Another way is to modify some VB.Net Webserver to a COM DLL. Also not THAT complicated simple VB.NET Webserver <<< Might be a good idea if you are on 64 bit. Anyhow if you got the Webserver thing up you can now showel your database datas into the webserver and let he deliver them to a shape by a URL. To be honest that all is pure overkill. I use a software ram disc for such purposes. For example Softperfect Ram disc. So there is no real file written cause it uses a small amount of memory for the virtual disc. Its damn fast cause the computer ram is used and after reboot everything is gone if you whish. Sure you might parse the database data by VBA and write the pixels little by little to the shape. Some guys have made a full image processor in vb6 which is nearly vba Photo Daemon So you can see how easy to decompose and compose images. I just hope that something might be usable for you. This is not really a "answer" but might give you some ideas. The pure VBA Webserver is nice if you get the winsocks running. Ive fooled around a bit with this as we was still on 32 bit - was funny :)

Thomas Ludewig
  • 696
  • 9
  • 17
  • The idea is to make it work without any addons etc. so I can pass this file to my co-workers without having to install some random stuff. But it's not cruical for me right now because we have links to image files in sql db... but just in case I am trying to implement ability to read directly form variable. There are hundreds of this images to be displayed at once so basically reading directly from variable might be also the fastest way. – Dam Gal Sep 09 '19 at 21:44
  • A pure VBA webserver would do the trick. can be emebdded even in the sheet. The problem i faced some years ago was that MS "forget" to provide a 64bit winsock.dll. You might try to use even in a 64bit environment this dll. There was some trick or registry hack if i remember right. As long you do not deal with pointers it might work. In my links is a very basic server. All he need to do is to decorate the base64 coded image datas with a fine http header and pump it trough the tcp stack on request. Main issue is stupidly the sock :/ Will be also no real race car. – Thomas Ludewig Sep 09 '19 at 23:29
0

This was tried three years ago and did not work directly from a variable. (see Inserting an Image into a sheet using Base64 in VBA?)

Giving up the "don't save to temporary file" idea and the whole thing is easy. (see How to embed a GIF image into an Excel file). Why not save it to a file? e.g. in a ram disk?

enter image description here

;-)

simple-solution
  • 1,109
  • 1
  • 6
  • 13
  • That something was not possible a few years ago does not means that its impossible at all .It just means that no one has got a splendid idea or was just to lazy to tell someone. :P – Thomas Ludewig Sep 09 '19 at 21:32
  • Still OP did not share with us why it's a problem to save the pictures to temporary files. ;-) – simple-solution Sep 09 '19 at 21:40
  • BTW - if the images comes already from a database - why not use a normal webserver connected to this database to deliver those images to the clients ? That might be a thalf a day task. – Thomas Ludewig Sep 09 '19 at 23:39
  • simple-solution, it's 10000 rows. So that's a lot of IO reading... first writing to disk then reading from it, which could be totally avoidable. We don't want file opening for 10 minutes... should be seconds. – Dam Gal Sep 10 '19 at 00:54