Version

Importing Shapes from Excel (Infragistics Excel Engine)

Topic Overview

Purpose

This topic shows you how to enumerate shapes from an Excel file.

Control Configuration Overview

Control configuration chart

The table below lists the configurable behaviors of the Infragistics Excel Engine.

Configuration behaviour Configuration details Configuration properties

Enumerate shapes from an Excel file

Read all shape instances from a worksheet

Enumerate shapes from an Excel file

Example description

You can enumerate the existing shapes in a worksheet by first loading the file into a Workbook instance. Then, using the Workbook.Worksheets collection, get the Worksheet instance and enumerate its Shapes property. This property is a WorksheetShapeCollection, which can be used to enumerate or modify the shapes on a Worksheet.

In Visual Basic:

Dim book As Workbook = Workbook.Load("..\..\test.xlsx")
For Each sheet As Worksheet In book.Worksheets
    For Each shape As WorksheetShape In sheet.Shapes
    Dim bounds As Rect = shape.GetBoundsInTwips()
        Console.WriteLine(
            [String].Format("ClassName:{0} – Bounds:{1},{2},{3},{4}",
                shape.[GetType](),
                bounds.X,
                bounds.Y,
                bounds.Width,
                bounds.Height))
    Next
Next

In C#:

Workbook book = Workbook.Load(@"..\..\test.xlsx");
foreach (Worksheet sheet in book.Worksheets)
{
    foreach (WorksheetShape shape in sheet.Shapes)
    {
        Rect bounds = shape.GetBoundsInTwips();
        Console.WriteLine(
            String.Format("ClassName:{0} – Bounds:{1},{2},{3},{4}",
                shape.GetType(),
                bounds.X,
                bounds.Y,
                bounds.Width,
                bounds.Height));
    }
}