This topic describes the API operations that are related to Shape objects of spreadsheet documents.
Shapes
ActiveWorkbook.ActiveSheet.Shapes
Obtains all Shape objects in the active worksheet.
Syntax
expression.ActiveWorkbook.ActiveSheet.Shapes
expression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // Obtain all Shape objects in the active worksheet. const shapes = await activeSheet.Shapes; }
Methods
ActiveWorkbook.ActiveSheet.Shapes.AddChart2()
Adds a chart.
Syntax
expression.ActiveWorkbook.ActiveSheet.Shapes.AddChart2({ Style, XlChartType, Left, Top, Width, Height })
expression: an Application object.
Parameters
Parameter
Type
Required
Description
Style
String
No
The chart style.
XlChartType
Enum
No
The type of the chart.
Left
Number
No
The position of the left edge of the chart. Unit: pixels.
Top
Number
No
The position of the top edge of the chart. Unit: pixels.
Width
Number
No
The width of the chart. Unit: pixels.
Height
Number
No
The height of the chart. Unit: pixels.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // Obtain all Shape objects in the active worksheet. const shapes = await activeSheet.Shapes; // Add a clustered column chart. await shapes.AddChart2(340, 51, 0, 0, 300, 300); }
ActiveWorkbook.ActiveSheet.Shapes.AddPicture()
Adds a picture.
Only the SDK for JavaScript V1.1.19 and later support this method.
Syntax
expression.ActiveWorkbook.ActiveSheet.Shapes.AddPicture({ FileName, LinkToFile, SaveWithDocument, Left, Top, Width, Height, Scale })
expression: an Application object.
Parameters
Parameter
Type
Required
Description
FileName
String
Yes
The file based on which you want to create the picture. The value must be a URL or a Base64-encoded string.
LinkToFile
Enum
Yes
Specifies whether to link the picture to the file from which the picture was created. If the value of the FileName parameter is a URL, set this parameter to -1.
SaveWithDocument
Enum
Yes
Specifies whether to save the picture with the document. This parameter must be set to msoTrue if LinkToFile is set to msoFalse.
Left
Number
No
The position of the left edge of the picture relative to the left edge of the worksheet. Unit: pixels.
Top
Number
No
The position of the upper edge of the picture relative to the upper edge of the worksheet. Unit: pixels.
Width
Number
No
The width of the picture. Unit: pixels.
Height
Number
No
The height of the picture. Unit: pixels.
Scale
Boolean
No
Specifies whether to calculate the width and height coordinates of the picture based on the scale of the worksheet.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // Obtain all Shape objects on the current worksheet. const shapes = await activeSheet.Shapes; // Add the picture. await shapes.AddPicture('Image URL', -1, 0); }
ActiveWorkbook.ActiveSheet.Shapes.Item(Index)
Obtains a single object in the drawing layer, such as an AutoShape, freeform, OLE object, or picture.
Only the SDK for JavaScript V1.1.4 and later support this method.
Syntax
expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index)
expression: an Application object.
Parameters
Parameter
Type
Required
Description
Index
number
Yes
The index number of the shape.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // Obtain all Shape objects on the current worksheet. const shapes = await activeSheet.Shapes; // Obtain the first shape. const shape = await shapes.Item(1) }
Properties
ActiveWorkbook.ActiveSheet.Shapes.Count
Returns the number of Shape objects in the active worksheet.
Syntax
expression.ActiveWorkbook.ActiveSheet.Shapes.Count
expression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // Obtain all Shape objects in the active worksheet. const shapes = await activeSheet.Shapes; // Query the number of shapes in the active worksheet. const count = await shapes.Count; console.log(count); }
Shape
ActiveWorkbook.ActiveSheet.Shapes.Item(Index)
Obtains a single Shape object.
Syntax
expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index)
expression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // Obtain all Shape objects in the active worksheet. const shapes = await activeSheet.Shapes; // Add a clustered column chart. await shapes.AddChart2(340, 51, 0, 0, 300, 300); // Obtain all Shape objects in the active worksheet. const newShapes = await activeSheet.Shapes; // Obtain a single Shape object. const shape = await newShapes.Item(1); }
Methods
ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Delete()
Deletes a Shape object.
Syntax
expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Delete()
expression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // Obtain all Shape objects in the active worksheet. const shapes = await activeSheet.Shapes; // Add a clustered column chart. await shapes.AddChart2(340, 51, 0, 0, 300, 300); // Obtain the data source of the shape. const source = await activeSheet.Range('A1:B4'); // Set the data source of the shape. await shape.Chart.SetSourceData(source, 1); // Delete the shape after 3,000 milliseconds. setTimeout(async () => { await shape.Delete(); }, 3000); }
ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Select()
Selects a Shape object.
Syntax
expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Select()
expression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // You can also use activeSheet = await app.ActiveSheet; // Obtain all Shape objects in the active worksheet. const shapes = await activeSheet.Shapes; // Add a chart. const shape = await shapes.AddChart2(340, 51, 0, 0, 300, 300); // Obtain the data source of the shape. const source = await activeSheet.Range('A1:B4'); // Set the data source of the shape. await shape.Chart.SetSourceData(source, 1); // Select a single shape. setTimeout(async () => { await shape.Select(); }, 3000); }
ActiveWorkbook.ActiveSheet.Shapes.Item(Index).SelectedModel()
Selects a shape.
Syntax
expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).SelectedModel()
expression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // You can also use activeSheet = await app.ActiveSheet; // Obtain all Shape objects in the active worksheet. const shapes = await activeSheet.Shapes; // Add a chart. const shape = await shapes.AddChart2(340, 51, 0, 0, 300, 300); await shape.SelectedModel(); }
ActiveWorkbook.ActiveSheet.Shapes.Item(Index).SelectedModels()
Selects a collection.
Syntax
expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).SelectedModels()
expression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // You can also use activeSheet = await app.ActiveSheet; // Obtain all Shape objects in the active worksheet. const shapes = await activeSheet.Shapes; // Add a chart. const shape = await shapes.AddChart2(340, 51, 0, 0, 300, 300); await shape.SelectedModels(); }
Properties
ActiveWorkbook.ActiveSheet.Shapes.Item(Index).ID
Returns the ID of a specific shape.
Syntax
expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).ID
expression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // Obtain all Shape objects in the active worksheet. const shapes = await activeSheet.Shapes; // Add a clustered column chart. await shapes.AddChart2(340, 51, 0, 0, 300, 300); // Obtain the ID of the shape. const id = await shape.ID; console.log(id);
ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Name
Returns the name of a specific Shape object.
Syntax
expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Name
expression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // Obtain all Shape objects in the active worksheet. const shapes = await activeSheet.Shapes; // Add a clustered column chart. await shapes.AddChart2(340, 51, 0, 0, 300, 300); // Obtain the name of the shape. const name = await shape.Name; console.log(name);
ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Title
Sets a title for a Shape object.
Syntax
expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Title
expression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // Obtain all Shape objects in the active worksheet. const shapes = await activeSheet.Shapes; // Add a clustered column chart. await shapes.AddChart2(340, 51, 0, 0, 300, 300); // Specify a title for the shape. shape.Title = 'Aliyun';
ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart
Returns a specific chart.
Syntax
expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).Chart
expression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // Obtain all Shape objects in the active worksheet. const shapes = await activeSheet.Shapes; // Add a clustered column chart. await shapes.AddChart2(340, 51, 0, 0, 300, 300); // Obtain a chart object. const chart = await shape.Chart;
ActiveWorkbook.ActiveSheet.Shapes.Item(Index).ImageUrl
Returns the download link to a picture of a specific Shape object.
Only JS-SDK V1.1.15 and later support this method.
Syntax
expression.ActiveWorkbook.ActiveSheet.Shapes.Item(Index).ImageUrl
expression: an Application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain the active worksheet in the active workbook. const activeSheet = await app.ActiveWorkbook.ActiveSheet; // Obtain all Shape objects in the active worksheet. const shapes = await activeSheet.Shapes; // Add a clustered column chart. await shapes.AddChart2(340, 51, 0, 0, 300, 300); // Obtain the download link to the picture. const ImageUrl = await shape.ImageUrl;