placing image in specified cell in excel
37 views (last 30 days)
Show older comments
adam campbell
on 20 Nov 2020
Answered: adam campbell
on 20 Nov 2020
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
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).
Accepted Answer
More Answers (0)
See Also
Categories
Find more on ActiveX in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!