ShapeCollection.AddOleObjectWithLinkedImage

ShapeCollection.AddOleObjectWithLinkedImage method

Add a linked picture.

public OleObject AddOleObjectWithLinkedImage(int upperLeftRow, int upperLeftColumn, int height, 
    int width, string sourceFullName)
ParameterTypeDescription
upperLeftRowInt32Upper left row index.
upperLeftColumnInt32Upper left column index.
heightInt32The height of the shape. In unit of pixels
widthInt32The width of the shape. In unit of pixels
sourceFullNameStringThe path and name of the source file for the linked image

Return Value

Picture Picture object.

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using Aspose.Cells.Drawing;
    using System;

    public class ShapeCollectionMethodAddOleObjectWithLinkedImageWithInt32Int32Int32Int32StringDemo
    {
        public static void Run()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            // Path to the image file to be linked
            string imagePath = "example.jpg";

            try
            {
                // Call the AddOleObjectWithLinkedImage method with specific parameters
                OleObject oleObject = worksheet.Shapes.AddOleObjectWithLinkedImage(
                    1,  // upperLeftRow
                    1,  // upperLeftColumn
                    200, // height
                    300, // width
                    imagePath); // sourceFullName

                // Set additional properties for the OleObject
                oleObject.DisplayAsIcon = false;
                oleObject.IsAutoSize = true;

                Console.WriteLine("OLE object with linked image added successfully.");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error executing AddOleObjectWithLinkedImage method: {ex.Message}");
            }

            // Save the workbook
            workbook.Save("AddOleObjectWithLinkedImageDemo.xlsx");
        }
    }
}

See Also