Skip to content

Commit 83564a4

Browse files
[PowerPoint] (Shape) Add placeholder snippet (#1035)
* [PowerPoint] (Shape) Add placeholder snippet * Fix typo
1 parent c506088 commit 83564a4

File tree

5 files changed

+152
-9
lines changed

5 files changed

+152
-9
lines changed

playlists-prod/powerpoint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shapes-by-type.yaml
9898
group: Shapes
9999
api_set:
100-
PowerPointApi: '1.4'
100+
PowerPointApi: '1.8'
101101
- id: powerpoint-shapes-add-modify-tables
102102
name: Add and modify tables
103103
fileName: add-modify-tables.yaml

playlists/powerpoint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/shapes/get-shapes-by-type.yaml
9898
group: Shapes
9999
api_set:
100-
PowerPointApi: '1.4'
100+
PowerPointApi: '1.8'
101101
- id: powerpoint-shapes-add-modify-tables
102102
name: Add and modify tables
103103
fileName: add-modify-tables.yaml

samples/powerpoint/shapes/get-shapes-by-type.yaml

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ name: Select shapes by type
44
description: Gets shapes in a slide based on their type, such as GeometricShape or Line.
55
host: POWERPOINT
66
api_set:
7-
PowerPointApi: '1.4'
7+
PowerPointApi: '1.8'
88
script:
9-
content: |-
9+
content: |
1010
document.getElementById("setup").addEventListener("click", () => tryCatch(setup));
1111
document.getElementById("change-lines").addEventListener("click", () => tryCatch(changeLines));
1212
document.getElementById("change-geometric-shapes").addEventListener("click", () => tryCatch(changeGeometricShapes));
13+
document.getElementById("get-placeholder-shapes").addEventListener("click", () => tryCatch(getPlaceholderShapes));
1314
1415
async function changeLines() {
1516
// Changes the dash style of every line in the slide.
@@ -48,6 +49,38 @@ script:
4849
});
4950
}
5051
52+
async function getPlaceholderShapes() {
53+
// Gets the placeholder shapes in the slide.
54+
await PowerPoint.run(async (context) => {
55+
// Get properties for every shape in the collection.
56+
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
57+
shapes.load("type,name");
58+
await context.sync();
59+
60+
const placeholderShapes = [];
61+
console.log(`Number of shapes found: ${shapes.items.length}`);
62+
shapes.items.forEach((shape) => {
63+
if (shape.type === PowerPoint.ShapeType.placeholder) {
64+
// Load placeholderFormat property.
65+
// PowerPoint throws an exception if you try to load this property on a shape that isn't a placeholder type.
66+
shape.load("placeholderFormat");
67+
placeholderShapes.push(shape);
68+
}
69+
});
70+
await context.sync();
71+
72+
console.log(`Number of placeholder shapes found: ${placeholderShapes.length}`);
73+
for (let i = 0; i < placeholderShapes.length; i++) {
74+
let currentPlaceholder: PowerPoint.PlaceholderFormat = placeholderShapes[i].placeholderFormat;
75+
let placeholderType = currentPlaceholder.type as PowerPoint.PlaceholderType;
76+
let placeholderContainedType = currentPlaceholder.containedType as PowerPoint.ShapeType;
77+
console.log(`Shape "${placeholderShapes[i].name}" placeholder properties:`);
78+
console.log(`\ttype: ${placeholderType}`);
79+
console.log(`\tcontainedType: ${placeholderContainedType}`);
80+
}
81+
});
82+
}
83+
5184
async function setup() {
5285
await PowerPoint.run(async (context) => {
5386
// Create shapes of different types.
@@ -58,27 +91,27 @@ script:
5891
left: 100,
5992
top: 100,
6093
height: 150,
61-
width: 150
94+
width: 150,
6295
});
6396
shapes.addGeometricShape(PowerPoint.GeometricShapeType.octagon, {
6497
left: 400,
6598
top: 300,
6699
height: 150,
67-
width: 150
100+
width: 150,
68101
});
69102
70103
// Create lines.
71104
shapes.addLine(PowerPoint.ConnectorType.elbow, {
72105
left: 400,
73106
top: 150,
74107
height: 20,
75-
width: 150
108+
width: 150,
76109
});
77110
shapes.addLine(PowerPoint.ConnectorType.curve, {
78111
left: 100,
79112
top: 300,
80113
height: 150,
81-
width: 20
114+
width: 20,
82115
});
83116
84117
await context.sync();
@@ -98,7 +131,7 @@ script:
98131
template:
99132
content: |-
100133
<section>
101-
<p>This sample shows how select and change shapes based on their types.</p>
134+
<p>This sample shows how to select and change shapes based on their types.</p>
102135
</section>
103136
<section>
104137
<h3>Setup</h3>
@@ -112,6 +145,8 @@ template:
112145
<p />
113146
<button id="change-geometric-shapes">Change geometric shapes</button>
114147
<p />
148+
<button id="get-placeholder-shapes">Get placeholder shapes</button>
149+
<p />
115150
</section>
116151
language: html
117152
style:
122 Bytes
Binary file not shown.

snippet-extractor-output/snippets.yaml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16657,6 +16657,78 @@ PowerPoint.ParagraphHorizontalAlignment:enum:
1665716657
});
1665816658
await context.sync();
1665916659
});
16660+
PowerPoint.PlaceholderFormat:class:
16661+
- >-
16662+
// Link to full sample:
16663+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shapes-by-type.yaml
16664+
16665+
16666+
// Gets the placeholder shapes in the slide.
16667+
16668+
await PowerPoint.run(async (context) => {
16669+
// Get properties for every shape in the collection.
16670+
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
16671+
shapes.load("type,name");
16672+
await context.sync();
16673+
16674+
const placeholderShapes = [];
16675+
console.log(`Number of shapes found: ${shapes.items.length}`);
16676+
shapes.items.forEach((shape) => {
16677+
if (shape.type === PowerPoint.ShapeType.placeholder) {
16678+
// Load placeholderFormat property.
16679+
// PowerPoint throws an exception if you try to load this property on a shape that isn't a placeholder type.
16680+
shape.load("placeholderFormat");
16681+
placeholderShapes.push(shape);
16682+
}
16683+
});
16684+
await context.sync();
16685+
16686+
console.log(`Number of placeholder shapes found: ${placeholderShapes.length}`);
16687+
for (let i = 0; i < placeholderShapes.length; i++) {
16688+
let currentPlaceholder: PowerPoint.PlaceholderFormat = placeholderShapes[i].placeholderFormat;
16689+
let placeholderType = currentPlaceholder.type as PowerPoint.PlaceholderType;
16690+
let placeholderContainedType = currentPlaceholder.containedType as PowerPoint.ShapeType;
16691+
console.log(`Shape "${placeholderShapes[i].name}" placeholder properties:`);
16692+
console.log(`\ttype: ${placeholderType}`);
16693+
console.log(`\tcontainedType: ${placeholderContainedType}`);
16694+
}
16695+
});
16696+
PowerPoint.PlaceholderType:enum:
16697+
- >-
16698+
// Link to full sample:
16699+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shapes-by-type.yaml
16700+
16701+
16702+
// Gets the placeholder shapes in the slide.
16703+
16704+
await PowerPoint.run(async (context) => {
16705+
// Get properties for every shape in the collection.
16706+
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
16707+
shapes.load("type,name");
16708+
await context.sync();
16709+
16710+
const placeholderShapes = [];
16711+
console.log(`Number of shapes found: ${shapes.items.length}`);
16712+
shapes.items.forEach((shape) => {
16713+
if (shape.type === PowerPoint.ShapeType.placeholder) {
16714+
// Load placeholderFormat property.
16715+
// PowerPoint throws an exception if you try to load this property on a shape that isn't a placeholder type.
16716+
shape.load("placeholderFormat");
16717+
placeholderShapes.push(shape);
16718+
}
16719+
});
16720+
await context.sync();
16721+
16722+
console.log(`Number of placeholder shapes found: ${placeholderShapes.length}`);
16723+
for (let i = 0; i < placeholderShapes.length; i++) {
16724+
let currentPlaceholder: PowerPoint.PlaceholderFormat = placeholderShapes[i].placeholderFormat;
16725+
let placeholderType = currentPlaceholder.type as PowerPoint.PlaceholderType;
16726+
let placeholderContainedType = currentPlaceholder.containedType as PowerPoint.ShapeType;
16727+
console.log(`Shape "${placeholderShapes[i].name}" placeholder properties:`);
16728+
console.log(`\ttype: ${placeholderType}`);
16729+
console.log(`\tcontainedType: ${placeholderContainedType}`);
16730+
}
16731+
});
1666016732
PowerPoint.Presentation:class:
1666116733
- >-
1666216734
// Link to full sample:
@@ -17219,6 +17291,42 @@ PowerPoint.Shape#left:member:
1721917291
currentLeft = 0;
1722017292
if (currentTop > slideHeight - 200) currentTop = 0;
1722117293
});
17294+
PowerPoint.Shape#placeholderFormat:member:
17295+
- >-
17296+
// Link to full sample:
17297+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shapes-by-type.yaml
17298+
17299+
17300+
// Gets the placeholder shapes in the slide.
17301+
17302+
await PowerPoint.run(async (context) => {
17303+
// Get properties for every shape in the collection.
17304+
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
17305+
shapes.load("type,name");
17306+
await context.sync();
17307+
17308+
const placeholderShapes = [];
17309+
console.log(`Number of shapes found: ${shapes.items.length}`);
17310+
shapes.items.forEach((shape) => {
17311+
if (shape.type === PowerPoint.ShapeType.placeholder) {
17312+
// Load placeholderFormat property.
17313+
// PowerPoint throws an exception if you try to load this property on a shape that isn't a placeholder type.
17314+
shape.load("placeholderFormat");
17315+
placeholderShapes.push(shape);
17316+
}
17317+
});
17318+
await context.sync();
17319+
17320+
console.log(`Number of placeholder shapes found: ${placeholderShapes.length}`);
17321+
for (let i = 0; i < placeholderShapes.length; i++) {
17322+
let currentPlaceholder: PowerPoint.PlaceholderFormat = placeholderShapes[i].placeholderFormat;
17323+
let placeholderType = currentPlaceholder.type as PowerPoint.PlaceholderType;
17324+
let placeholderContainedType = currentPlaceholder.containedType as PowerPoint.ShapeType;
17325+
console.log(`Shape "${placeholderShapes[i].name}" placeholder properties:`);
17326+
console.log(`\ttype: ${placeholderType}`);
17327+
console.log(`\tcontainedType: ${placeholderContainedType}`);
17328+
}
17329+
});
1722217330
PowerPoint.Shape#top:member:
1722317331
- >-
1722417332
// Link to full sample:

0 commit comments

Comments
 (0)