Paste image from Delphi app into Excel

Posted on 2006-05-25
Last Modified: 2010-04-05
Hi folks,

I'm fairly new to OLE, so bare with me.  My terminology propbably leaves a lot to be desired :)

I've created an app which basically dumps a heap of formatted data into a speadsheet.  I'd like to include a few bitmaps which I create dynamically as well (but do not want to save them to disk).

Is it possible to stream a TBitmap to Excel use OLE and put it in a given range?

If it's not possible to do via a stream, is it possible to just paste it in (put the bitmap in to the clipboard, then paste it using VBA or something)?

I do not want to save the image to file first.

Any help greatly appreciated!


Question by:Stuart_Johnson
    LVL 11

    Expert Comment

    The pictures that you want to paste to Excel exist somewhere... don't they? So why saving them again on disk if they already are there... I suggest you to try copying to the clipboard and paste them where you need them. I did not try it yet but it should work with copy/paste.

    Also try recording a macro for inserting a picture in excel and from the macro learn how it works and then automate it.
    There are a lot of examples out there on how to automate excel

    LVL 6

    Author Comment

    The picture is generated in-memory by my program, so it doesn't exist anywhere else.

    I am trying to work out how to do the copy/paste.  I can not find an example on doing it with a graphic which is why I was asking here.



    Expert Comment

    Hey Stu,

    I've done something similar to the second idea you floated but I can't find the code anywhere right now...  Basically I pushed the TBitmap to the Windows clipboard and then had a small bit of VBA that I would call through an Excel OLE object that would pull that down and insert it.... If I remember correctly it wasn't extremely fast and I could never figure out which side it was on but I had my suspicions that it was on the VBA side.

    Anyway drop me a line on my hotmail at "gabenick" when you get a chance to let me know how you're doing!  Been a long time since we talked :)

    LVL 6

    Author Comment

    Hey Gabe dude.  How's it going?

    I've sort of got this going with a bit of VBA already, but I'm not overly happy with it.  When the image gets pasted into the cell, I get a warning that the dimensions of the object being pasted is larger than the target cell (or something like that).  I'm trying to find out how to paste without showing the error message more than anything else.

    Will drop you an email over the weekend.  I'm as busy as a one legged man in an arse kicking contest at the moment.

    Cheers dude,


    (PS.  How come you're still GabeinOZ?  You should be GabeInUS now LOL )

    Accepted Solution

    Yeah I was thinking about changing it but then I would lose all this mojo I have built up under that name and I'm gonna be back in Oz within the next couple months so its a moot point now :)

    Anyway, if I remember correctly I had the same issue you are describing with the error message and what I did was calculated the cell(s) size that I wanted to paste into and pre-selected that area in the VBA before the paste and it didn't throw the message.  Its the same as if you highlight 4 cells and do a copy and then highlight a three cell area and try to paste, it will throw the same error but if you highlight a 4 cell area (or just a single cell) it will let you paste all four copied cells fine.  Hope that helps... :)

    Later mate..

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
    Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now