alexa
menu

MAUI

  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Search Results for

    Show / Hide Table of Contents

    Interface IOleObject

    Represent the Ole object shapes.

    Namespace: Syncfusion.XlsIO
    Assembly: Syncfusion.XlsIO.NET.dll
    Syntax
    public interface IOleObject

    Properties

    DisplayAsIcon

    Gets or sets a value indicating whether [display as icon].

    Declaration
    bool DisplayAsIcon { get; set; }
    Property Value
    Type Description
    bool

    true if [display as icon]; otherwise, false.

    Examples

    The following code illustrates how to set DisplayAsIcon property.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Create image stream
        System.Drawing.Image image = System.Drawing.Image.FromFile("image.png");
    
        //Add ole object
        IOleObject oleObject = worksheet.OleObjects.Add("Shapes.xlsx", image, OleLinkType.Embed);
    
        //Set display as icon
        oleObject.DisplayAsIcon = true;
    
        //Save and dispose
        workbook.SaveAs("OLEObjects.xlsx");
        workbook.Close();
    }

    Location

    Gets or sets the location.

    Declaration
    IRange Location { get; set; }
    Property Value
    Type Description
    IRange

    The location.

    Examples

    The following code illustrates how to set the Location property.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Create image stream
        System.Drawing.Image image = System.Drawing.Image.FromFile("image.png");
    
        //Add ole object
        IOleObject oleObject = worksheet.OleObjects.Add("Shapes.xlsx", image, OleLinkType.Embed);
    
        //Set height and width
        oleObject.Shape.Height = 150;
        oleObject.Shape.Width = 150;
    
        //Set location
        oleObject.Location = worksheet["C7"];
    
        //Save and dispose
        workbook.SaveAs("OLEObjects.xlsx");
        workbook.Close();
    }

    Name

    Gets the name of an OLE object.

    Declaration
    string Name { get; }
    Property Value
    Type
    string
    Examples

    The following code illustrates how to access Name property.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Create image stream
                System.Drawing.Image image = System.Drawing.Image.FromFile("image.png");
    
                //Add ole object
                IOleObject oleObject = worksheet.OleObjects.Add("Shapes.xlsx", image, OleLinkType.Embed);
    
                //Get name
                Console.WriteLine(oleObject.Name);
    
                //Save and dispose
                workbook.SaveAs("OLEObjects.xlsx");
                workbook.Close();
                Console.ReadKey();
            }
    //Output will be
    //Picture0

    Picture

    Gets or sets the picture.

    Declaration
    Image Picture { get; }
    Property Value
    Type Description
    Image

    The picture.

    Examples

    The following code illustrates how to access Picture property.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Create image stream
                System.Drawing.Image image = System.Drawing.Image.FromFile("image.png");
    
                //Add ole object
                IOleObject oleObject = worksheet.OleObjects.Add("Shapes.xlsx", image, OleLinkType.Embed);
    
                //Get picture's height and width
                Console.WriteLine(oleObject.Picture.Height);
                Console.WriteLine(oleObject.Picture.Width);
    
                //Save and dispose
                workbook.SaveAs("OLEObjects.xlsx");
                workbook.Close();
                Console.ReadKey();
            }
    //Output will be
    //{Given image's height}
    //{Given image's width}

    Shape

    Gets or sets picture shape object that defines look and position of the OleObject inside parent worksheet.

    Declaration
    IPictureShape Shape { get; }
    Property Value
    Type
    IPictureShape
    Examples

    The following code illustrates how to set HeightDouble and WidthDouble of the Picture by accessing Shapes property.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Create image stream
        System.Drawing.Image image = System.Drawing.Image.FromFile("image.png");
    
        //Add ole object
        IOleObject oleObject = worksheet.OleObjects.Add("Shapes.xlsx", image, OleLinkType.Embed);
    
        //Set height and width
        oleObject.Shape.HeightDouble = 150;
        oleObject.Shape.WidthDouble = 150;
    
        //Save and dispose
        workbook.SaveAs("OLEObjects.xlsx");
        workbook.Close();
    }

    Size

    Gets or sets the size.

    Declaration
    Size Size { get; set; }
    Property Value
    Type Description
    Size

    The size.

    Examples

    The following code illustrates how to access Size property.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Create image stream
                System.Drawing.Image image = System.Drawing.Image.FromFile("image.png");
    
                //Add ole object
                IOleObject oleObject = worksheet.OleObjects.Add("Shapes.xlsx", image, OleLinkType.Embed);
    
                //Get image size
                Console.WriteLine(oleObject.Size.Height);
                Console.WriteLine(oleObject.Size.Width);
    
                //Save and dispose
                workbook.SaveAs("OLEObjects.xlsx");
                workbook.Close();
                Console.ReadKey();
            }
    //Output will be
    //{Prints given image's height}
    //{Prints given image's width}

    Methods

    GetEmbeddedOleStream()

    /// Gets the OLE part stream.

    Declaration
    Stream GetEmbeddedOleStream()
    Returns
    Type
    Stream
    Examples

    The following code illustrates how to get the OLE part stream.

    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        //Create worksheet
        IApplication application = excelEngine.Excel;
        IWorkbook workbook = application.Workbooks.Create(1);
        IWorksheet worksheet = workbook.Worksheets[0];
    
        //Create file stream and image stream
        FileStream inputStream = new FileStream("Sample.xlsx", FileMode.Open);
        FileStream imageStream = new FileStream("image.png", FileMode.Open);
    
        //Create image stream
        Syncfusion.Drawing.Image image = Syncfusion.Drawing.Image.FromStream(imageStream);
    
        //Add ole object
        IOleObject oleObject = worksheet.OleObjects.Add(inputStream, image, OleObjectType.ExcelWorksheet);
    
        // Get the OLE part stream.
        Image image1 = Image.FromStream(worksheet.OleObjects[0].GetEmbeddedOleStream());
        MemoryStream memory = new MemoryStream(image1.ImageData);
    
        //Saving the workbook as stream
        FileStream stream = new FileStream("ExtractedFile.xlsx", FileMode.Create, FileAccess.Write);
        memory.CopyTo(stream);
        workbook.SaveAs(stream);
        stream.Dispose();
    }
    In this article
    Back to top Generated by DocFX
    Copyright © 2001 - 2026 Syncfusion Inc. All Rights Reserved