Support for placing images with respective to its absolute position in sheets

Hello Aspose team,

I am going to place the two images(or more than one) in the sheets with respective to it’s absolute position. First, I have inserted the images at (0,0) position of the sheet and tried to move the image in the sheet.I used the following code for that :-

FileInputStream io = new FileInputStream(new File(“singlesheet.xlsx”));
Workbook workbook = new Workbook(io);
def ws = workbook.getWorksheets().get(“Display”)

int i = ws.getPictures().add(0, 0, “/home/nregmi/aaBackup/chart.png”)
Picture pic01 = ws.getPictures()[i]
pic01.setHeightInch(0)
pic01.setWidthInch(1.42)

int j = ws.getPictures().add(0, 0, “/home/nregmi/aaBackup/chart.png”)
Picture pic02 = ws.getPictures()[j]
pic02.setHeightInch(0)
pic02.setWidthInch(1.42*2)

When I placed the first image then it was correctly placed in the given position but when second image was inserted then the images were distorted in the sheets.Can you please tell me what am I doing wrong here?

I have attached the required resources used in this thread.
resources.zip (29.1 KB)

@niteshregmi1234,

Thanks for the template file, sample code and image file.

I tested your scenario/ case using the following sample code with latest version/fix: v19.10 (please try it if you are not already using it), it works fine and I could not find any issue in the output file (attached):
e.g
Sample code:

FileInputStream io = new FileInputStream(new File("e:\\test2\\singlesheet.xlsx"));
         Workbook workbook = new Workbook(io);
         Worksheet ws = workbook.getWorksheets().get("Display");

         int i = ws.getPictures().add(0, 0, "e:\\test2\\chart.png");
         Picture pic01 = ws.getPictures().get(i);
         pic01.setHeightInch(0);
         pic01.setWidthInch(1.42);
                     
         int j = ws.getPictures().add(0, 0, "e:\\test2\\chart.png");
         Picture pic02 = ws.getPictures().get(j);
         pic02.setHeightInch(0);
         pic02.setWidthInch(1.42*2);
         
         workbook.save("f:\\files\\out1.xlsx");

Also, see the screenshots which give correct height/width values (it is in cm but if we convert these cm values to inches, these are same values as per the code):


files1.zip (32.7 KB)

If you still find any issue, kindly do elaborate the issue and provide more details with sample code and screenshots, we will check it soon.

@Amjad_Sahi

There was a mistake from my side to elaborate my problem.I was going to move the image in the sheet. The correct code is written below :-

FileInputStream io = new FileInputStream(new File(“e:\test2\singlesheet.xlsx”));
Workbook workbook = new Workbook(io);
Worksheet ws = workbook.getWorksheets().get(“Display”);

     int i = ws.getPictures().add(0, 0, "e:\\test2\\chart.png");
     Picture pic01 = ws.getPictures().get(i);
     pic01.setHeight(80);
     pic01.setWidth(210);
     pic01.setLeftInch(1.42)
     pic01.setTopInch(0)

                 
     int j = ws.getPictures().add(0, 0, "e:\\test2\\chart.png");
     Picture pic02 = ws.getPictures().get(j);
     pic02.setHeight(80);
     pic02.setWidth(210);
     pic02.setLeftInch(1.42*2)
     pic02.setTopInch(0)
     
     workbook.save("f:\\files\\out1.xlsx");

The first picture is placed in the required position but when another image is inserted than the image in sheets is distorted.Can you please look at this.

@niteshregmi1234,
We are working on this issue and need an expected output file generated by Excel for our reference. It will help us to analyze the issue and provide assistance.

@ahsaniqbalsidiqui

I have attached the output here. Hope this helps.

resourceOutput.zip (39.6 KB)

@niteshregmi1234,

Thanks for the file.

This is probably your output file by Aspose.Cells.

As requested, we need your expected file that you may generate MS Excel and attach it. We will check it soon.

@Amjad_Sahi @ahsaniqbalsidiqui

I have attached the expected output file here.expectedOutput file.zip (34.1 KB)

Thanks,

@niteshregmi1234,
You may please try setting the X and Y values in unit of pixels and share the feedback. It will move the picture at the specified location set by X and Y.

Workbook workbook = new Workbook(io);
Worksheet ws = workbook.getWorksheets().get("Display");

 int i = ws.getPictures().add(0, 0, "chart.png");
 Picture pic01 = ws.getPictures().get(i);
 pic01.setHeight(80);
 pic01.setWidth(210);
 pic01.setX(0);
 pic01.setY(0);

 int j = ws.getPictures().add(0, 0, "chart.png");
 Picture pic02 = ws.getPictures().get(j);
 pic02.setHeight(80);
 pic02.setWidth(210);
 pic01.setX(0);
 pic01.setY(120);
 workbook.save("outUser.xlsx");

@ahsaniqbalsidiqui
Yes it works in my sample project. I will implement it in my main project and will let you know if any problem arises.

@niteshregmi1234,
Sure. Let us know your feedback then.