Is there a way in EPPlus to programatically insert and image into a cell.
(if you run this code in VBA in a recent version of Excel) it will imbed the image and save the image in the sheet.
Thanks in advance,
Steve . . .
Sub InsertPictureInCell(cellAddress As String, filePath As String)
Dim ws As Worksheet
Dim pic As Picture
' Set the worksheet where you want to insert the picture
Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name
' Insert the picture
Set pic = ws.Pictures.Insert(filePath)
' Position the picture over cells
With pic
.Top = ws.Range(cellAddress).Top
.Left = ws.Range(cellAddress).Left
.Placement = 1 ' xlMoveAndSize
End With
Set shp = ws.Shapes(pic.Name)
' Call the custom method PlacePictureInCell
‘ shp.PlacePictureInCell
Range(cellAddress).Select
ActiveSheet.Shapes.Range(Array(pic.Name)).Select
ws.Shapes(pic.Name).PlacePictureInCell
End Sub
Sub TestInsertPictureInCell()
InsertPictureInCell “A1”, “C:Image.png”
End Sub
I tried a few examples but could only get an overlayed image not an imbeddedimage
InsertPictureInCell / PlacePictureInCell
Steve Dickson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.