Hi Team,

I have an excel which has multiple rows and each row can have multiple images associated with that , which are postioned on a specific cells of that particular row.I know while we are positioning a image on top of a cell, that is not associated with the cell and it is actually floting the sheet of the workbook.My target is to read those images and at the same time mapping that image with particular cell using apche POI. I have two questions actually:

  1. Is there any way to associate an image with a excel cell so that I can read the image using POI as a cell property?
  2. If above point is not feasible, then is there any way that I can read the image from the excel and map that images with particular rows?

**I have attached the sample data.

I have already treid cell.getSheet().getWorkbook().getAllPictures().. But that is returning all the images, but I don't understand which image is positioned on top of which cell.

Any help will be highly appreciated. I am waiting for your reply :).

Hi, it is not possible to read an image from a cell as a cell property. If you only want to read the images from a worksheet and reposition them on a specific cell, refer to the following code snippet. This requires another free Excel API instead of POI.

import com.spire.xls.*;

public class ChangeImagePosition {

    public static void main(String[] args) {

        //Create a Workbook object
        Workbook wb= new Workbook();

        //Load an Excel file
        wb.loadFromFile("C:\\Users\\Administrator\\Desktop\\images.xlsx");

        //Get the first image
        ExcelPicture excelPicture = wb.getWorksheets().get(0).getPictures().get(0);

        //Place the image on a specific row and column
        excelPicture.setTopRow(1);
        excelPicture.setLeftColumn(2);

        //Save to file
        wb.saveToFile("output/ChangePicPosition.xlsx",ExcelVersion.Version2016);
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.