How to Insert Picture in Cell with C++

Possible Usage Scenarios

The image adds a touch of brightness to your worksheet and provides a visual representation of the content. It also makes it easier for you to understand the data and come up with insights. Although you have been able to use images in Excel for many years, Excel has only recently enabled the feature of images becoming actual cell values. Even if the layout of the drawing is modified, it will still be attached to the data. You can use it in tables, sort, filter, include it in formulas, and so on!

How to Insert Picture in Cell Using Excel

To insert a picture into a cell in Excel, follow these steps:

  1. Go to the Insert tab and click on the Pictures option.
  2. Select Place in Cell. Choose one of the following sources from the Insert Picture From dropdown menu (This device, Stock Images, and Online Pictures). This device inserts a picture from your computer. Stock Images inserts a picture from the built‑in collection. Online Pictures inserts a picture from the web.


  3. Select a picture and insert it into a cell.


How to Insert Picture over Cells Using Excel

To insert a picture over cells in Excel, follow these steps:

  1. Go to the Insert tab and click on the Pictures option.
  2. Select Place over Cells. Choose one of the following sources from the Insert Picture From dropdown menu (This device, Stock Images, and Online Pictures). This device inserts a picture from your computer. Stock Images inserts a picture from the built‑in collection. Online Pictures inserts a picture from the web.


  3. Select a picture and insert it over cells.


How to Switch from Picture in Cell to Picture over Cells Using Excel

You can easily switch from Picture in Cell to Picture over Cells. Please follow these steps:

  1. Right‑click on the cell and select Picture in Cell → Place over Cells.


  2. The result after switching is as follows:


How to Switch from Picture over Cells to Picture in Cell Using Excel

You can easily switch from Picture over Cells to Picture in Cell. Please follow these steps:

  1. Right‑click on the picture and select Place in Cell.


  2. The result after switching is as follows:


How to Insert Picture in Cell Using C++

Insert a picture in a cell using Aspose.Cells. See the following sample code. After executing the example code, a picture will be inserted into a cell.

  1. Instantiate a Workbook object.
  2. Get the cell where you want to insert the picture.
  3. Set the Cell.EmbeddedImage property.
  4. Finally, it saves the workbook in the output XLSX format.

Sample Code

#include <iostream>
#include <fstream>
#include <vector>
#include "Aspose.Cells.h"

using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // Create a new workbook
    Workbook workbook;

    // Get the first worksheet
    Worksheet worksheet = workbook.GetWorksheets().Get(0);

    // Get cell D8
    Cell d8 = worksheet.GetCells().Get(u"D8");

    // Read image file into byte vector
    std::ifstream file("aspose.png", std::ios::binary);
    std::vector<uint8_t> imageData((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());

    // Convert to Aspose's Vector and set embedded image in cell D8
    d8.SetEmbeddedImage(Vector<uint8_t>(imageData.data(), imageData.size()));

    // Save the workbook
    workbook.Save(u"out.xlsx");

    Aspose::Cells::Cleanup();
    return 0;
}