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

Free Support Forum - aspose.com

Position image in Excel

Hi all,

I need to position an image in the center of a RangeNamed cell. How can i do that ?

// PNG

xmlTag = String.Format(“SIGNATURE_{0}_PNG”, level);

range = workbook.Worksheets.GetRangeByName(xmlTag);

if (range != null)

{

Worksheet worksheet = range.Worksheet;

int i = worksheet.Pictures.Add(range.FirstRow, range.FirstColumn, pngStream);
Picture p = worksheet.Pictures[i];
p.Name = xmlTag;
p.UpperDeltaX = ???
p.UpperDeltaY = ???
}

Thanks you

Hi,


Please see the following two code snippets for your reference:

1)
//Instantiating an Workbook object
Workbook workbook = new Workbook(“e:\test2\Book1.xlsx”);

//Obtaining the reference of first worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];


//Adding a picture at the location of a cell whose row and column indices
//are 5 in the worksheet. It is “F6” cell
int pictureIndex = worksheet.Pictures.Add(5, 5, “e:\test\chartimage.jpg”);


//Accessing the newly added picture
Aspose.Cells.Drawing.Picture picture = worksheet.Pictures[pictureIndex];


//Positioning the picture proportional to row height and colum width
picture.UpperDeltaX = 200;
picture.UpperDeltaY = 200;

picture.LowerDeltaX = 200;
picture.LowerDeltaY = 200;
//Saving the Excel file
workbook.Save(“e:\test2\picturesposit.xls”);

2)
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells.SetRowHeight(3, 120);
worksheet.Cells.SetColumnWidth(6, 20);
//Fit to G4 cell.
int index = worksheet.Pictures.Add(3, 6, 4, 7, “e:\test\school.jpg”);
Aspose.Cells.Drawing.Picture pic = worksheet.Pictures[index];
pic.Placement = PlacementType.FreeFloating;
workbook.Save(“e:\test2\pichw2.xls”);