none
How to Paste Multiple Copies of an Image in Excel?

    Question

  • I have an Excel 2010 document add-in which creates many reports.  Part of the reports include pasting the same image.  The image can be inserted dozens of times.

    I have it working fine now reading the image file from disk each time via worksheet.shapes.addpicture

    But I am running into some very difficult to track down out of memory issues and would like to change the logic to only read the file from disk once and then just keep pasting this same in memory image each time it is needed.  I have found references to .NET throwing out of memory errors when it has problems reading images, so I want to minimize the number of times it reads the image from disk.  It also seems more efficient to just read once.  I feel like it should be easy but seem to be missing something.

     

    I have been investigating system.drawing.image and worksheet.shapes and cannot seem to find the right commands to:

    1) read an image file (PNG) from disk into memory

    2) paste/insert that image from memory onto worksheets in a workbook, n-number of times.

     

    Help?

     

    -Denis Burke


    • Edited by burkeden Saturday, January 28, 2012 2:02 AM typo in title
    Thursday, January 26, 2012 1:17 PM

Answers

  • Hi Denis

    Excel has no way to "stream" an image into an opened workbook. Closest you can get would be to place the information on the Clipboard and then Paste it as required.

    Another possibility might be to copy the first instance of the image you insert, then copy/paste that as required.

    But I'm not sure either of these options would reduce the problem you're encountering.

    If you were generating these workbooks outside the Excel application, using Open XML, then what you want to do would be possible.


    Cindy Meister, VSTO/Word MVP
    Thursday, January 26, 2012 4:38 PM

All replies

  • Hi Denis

    Excel has no way to "stream" an image into an opened workbook. Closest you can get would be to place the information on the Clipboard and then Paste it as required.

    Another possibility might be to copy the first instance of the image you insert, then copy/paste that as required.

    But I'm not sure either of these options would reduce the problem you're encountering.

    If you were generating these workbooks outside the Excel application, using Open XML, then what you want to do would be possible.


    Cindy Meister, VSTO/Word MVP
    Thursday, January 26, 2012 4:38 PM
  • Thanks Cindy - that clears it up!
    Thursday, January 26, 2012 7:09 PM