Insert picturebox image to a worksheet range C#

I have a picturebox control that contains an image. I am having a problem trying to add the image to a worksheet picture in a given range (eg. b3:e6). Can you provide an example of how this might be done. I have seen examples of inserting an image file (png, jpg etc.), but would like to avoid converting the picturebox image to a file and then inserting into the worksheet.


Hi Lindsey,

You can save the PictureBox.Image to a stream and then insert that stream into a worksheet.
For example:

var stream = new MemoryStream();
this.pictureBox1.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
stream.Position = 0;

worksheet.Pictures.Add(stream, ExcelPictureFormat.Png,
    new AnchorCell(worksheet.Cells["B3"], true),
    new AnchorCell(worksheet.Cells["E6"], false));

I hope this helps.