ShapeCollection.AddFreeFloatingShape

ShapeCollection.AddFreeFloatingShape method

Adds a free floating shape to the worksheet.Only applies for line/image shape.

public Shape AddFreeFloatingShape(MsoDrawingType type, int top, int left, int height, int width, 
    byte[] imageData, bool isOriginalSize)
ParameterTypeDescription
typeMsoDrawingTypeThe shape type.
topInt32Represents the vertical offset of shape from the worksheet’s top row, in unit of pixel.
leftInt32Represents the horizontal offset of shape from the worksheet’s left column, in unit of pixel.
heightInt32Represents the height of LineShape, in unit of pixel.
widthInt32Represents the width of LineShape, in unit of pixel.
imageDataByte[]The image data,only applies for the picture.
isOriginalSizeBooleanWhether the shape use original size if the shape is image.

Examples

using System;
using System.IO;
using Aspose.Cells;
using Aspose.Cells.Drawing;

namespace AsposeCellsExamples
{
    public class ShapeCollectionMethodAddFreeFloatingShapeWithMsoDrawingTypeInt32Int32Int32IDemo
    {
        public static void Run()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];
            ShapeCollection shapes = worksheet.Shapes;

            // Add a line shape
            Shape floatingShape_Line = shapes.AddFreeFloatingShape(
                MsoDrawingType.Line, 
                100, 100, 100, 50, 
                null, 
                false);

            // Add a picture shape (using sample image data)
            byte[] imageData = null;
            try
            {
                using (FileStream fs = new FileStream("image.jpg", FileMode.Open))
                {
                    imageData = new byte[fs.Length];
                    fs.Read(imageData, 0, (int)fs.Length);
                }
            }
            catch
            {
                // Create dummy image data if file not found
                imageData = new byte[100];
            }

            Shape floatingShape_Picture = shapes.AddFreeFloatingShape(
                MsoDrawingType.Picture, 
                200, 100, 100, 50, 
                imageData, 
                false);

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

See Also