We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Center image in merged cells

Hi
i have merged cells from A1 to K1
i want to insert image and center it horizontally in the middle of merged cells
i’m using aspose cells version 8.7

@AKawamleh,

Thanks for your query.

Well, you need to evaluate the widths of the merged cells range and then calculate the width of the image. Now write your own logic and code by yourself to place it in the center of the merged cells area. See the following sample code that works fine on my end for my specific case:
e.g
Sample code:

 Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            worksheet.Cells.SetRowHeight(0, 140);

            int widths = worksheet.Cells.GetColumnWidthPixel(0) * 11;

                                    
            worksheet.Cells.Merge(0, 0, 1, 11);

            int index = worksheet.Pictures.Add(0, 0,"e:\\test\\school.jpg");


            //Place it in the center of the merged cell(s) area.
            worksheet.Pictures[index].X = worksheet.Pictures[index].Left + (widths - worksheet.Pictures[index].Width)/2;


            workbook.Save("e:\\test2\\out1.xlsx");

thank you ,it works just fine for me.

@AKawamleh,

Good to know that your issue is sorted out. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.