Documents for Excel .NET Edition | GCDocuments
Features / Shapes and Pictures / Size and Position of Image
In This Topic
    Size and Position of Image
    In This Topic

    Sometimes, it is required to render an image in a worksheet at a specific position. In such cases, it becomes very difficult to determine the position or size of the image by traversing through the cells of the worksheet.

    GcExcel allows you to know the size and absolute position of an image by using GetRangeBoundary method of type Rectangle in the CellInfo class. The method returns the location and size of the image (in pixels).

    Using Code

    Refer to the following example code to get the location and size of an image by adding it at a specified range in a worksheet.

    Copy Code
    IWorkbook workbook = new Workbook();
    IWorksheet worksheet = workbook.ActiveSheet;
    IRange range = worksheet.Range["D4:H8"];
    // Get the absolute location and size of the Range["D4:H8"] in the worksheet.
    Rectangle rect = CellInfo.GetRangeBoundary(range);
    Console.WriteLine("The location and size of the image:" + rect);
    // Add the image to the Range["D4:H8"].
    worksheet.Shapes.AddPictureInPixel("image.png", rect.X, rect.Y, rect.Width, rect.Height);