Images
An image on a worksheet is not a cell value. It sits on a drawing overlay that
floats above the grid, so nothing about the cell underneath it changes and
reading that cell returns whatever it held before. A sheet has room for exactly
one drawing, which means every image and every chart on the sheet shares it.
Build one drawing, add everything to it, then hand it to the sheet with
SetDrawing.
What decides where the image lands is the anchor you ask for when you call
Drawing.AddImage. AnchorTypeAbsolute pins it to a fixed offset from the
top-left of the sheet, AnchorTypeOneCell pins the top-left corner to a cell
and keeps a fixed size, and AnchorTypeTwoCell pins both corners so the image
moves and resizes with the rows and columns it spans. All three satisfy the same
Anchor interface, and the methods that don’t apply to a given anchor type are
silent no-ops rather than errors. That is the single thing most likely to waste
your afternoon, so the insert guide leads with it.
Extraction is the reverse trip, and worth knowing about if you are handed
workbooks produced elsewhere. Sheet.Images() walks the sheet’s drawing
relationships and returns the images in the order they are related, as the bytes
that were stored, in whatever format the original author used.
Where to look
| Guide | Covers |
|---|---|
| Insert Images | Adding an image to a drawing and anchoring it. |
| Extract Images | Pulling images out of an existing workbook. |