placing image in specified cell in excel

37 views (last 30 days)
Hello,
I'm trying to figure out how i can place an image in a specified cell range, specifically one that is merged and centered.
ideally i would like to place the upper left hand corner of the image in the upper left hand corner of the specified cell.
i'm currently using the following code to place the image into excel, with specified dimensions. i'm iterating through a loop to manually place them in a position using 'Points'. I would like to get away from having to increment the dimensions in the loop because it is causing a shift in my image over a large directory of images. attached is the code i'm using to add the picture and increment the dimension/placement of it.
barcodepics = Shapes.AddPicture([DIR '\Barcodes\' image] ,dimensions(2,1), dimensions(2,2),...
dimensions(2,3),dimf2, dimensions(2,5), dimensions(2,6)); %
UPDATE: i have found this function that will write a figure to a specified cell range, maybe this could be slightly altered to allow for an image pull from a directory?
UPDATE(2):
I have also found this piece of code w/ the following results:
I'm wondering if it would be possible to add this into my existing Shapes.AddPicture code?
  2 Comments
Rik
Rik on 20 Nov 2020
You can use the clipboard function to interact with the clipboard. (so you can read the images from the file, then use clipboard to copy the image to the clipboard, then use this ActiveX-server to paste it in your excel file)
Note that ActiveX controls will be removed at some point in the future and only(?) work on Windows. This mechanism will also fail if you touch your pc during execution (as changing the clipboard contents or interacting with Excel might mess up the result).
adam campbell
adam campbell on 20 Nov 2020
can you copy images in matlab to the clipboard without creating a figure / figure handle?
i'm trying to avoid using the figure handle because it adds white background to my image when i paste it.

Sign in to comment.

Accepted Answer

adam campbell
adam campbell on 20 Nov 2020
Rik,
I've answered my own question....

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!