Skip to content

Commit edfe801

Browse files
[PowerPoint] Add manage-hyperlinks (OfficeDev#936)
* [PowerPoint] Add manage-hyperlinks * Tweak * Apply suggestions from code review Co-authored-by: Alex Jerabek <[email protected]> * Run yarn start --------- Co-authored-by: Alex Jerabek <[email protected]>
1 parent 75101a1 commit edfe801

File tree

7 files changed

+132
-0
lines changed

7 files changed

+132
-0
lines changed

playlists-prod/powerpoint.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@
5454
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/images/insert-svg.yaml
5555
group: Images
5656
api_set: {}
57+
- id: powerpoint-manage-hyperlinks
58+
name: Get hyperlinks
59+
fileName: manage-hyperlinks.yaml
60+
description: Gets the hyperlinks found in a slide.
61+
rawUrl: >-
62+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/manage-hyperlinks.yaml
63+
group: Preview APIs
64+
api_set:
65+
PowerPointApi: '1.6'
5766
- id: powerpoint-scenarios-searches-wikipedia-api
5867
name: Search Wikipedia
5968
fileName: searches-wikipedia-api.yaml

playlists/powerpoint.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@
5454
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/images/insert-svg.yaml
5555
group: Images
5656
api_set: {}
57+
- id: powerpoint-manage-hyperlinks
58+
name: Get hyperlinks
59+
fileName: manage-hyperlinks.yaml
60+
description: Gets the hyperlinks found in a slide.
61+
rawUrl: >-
62+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/preview-apis/manage-hyperlinks.yaml
63+
group: Preview APIs
64+
api_set:
65+
PowerPointApi: '1.6'
5766
- id: powerpoint-scenarios-searches-wikipedia-api
5867
name: Search Wikipedia
5968
fileName: searches-wikipedia-api.yaml
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
id: powerpoint-manage-hyperlinks
2+
name: Get hyperlinks
3+
description: Gets the hyperlinks found in a slide.
4+
host: POWERPOINT
5+
api_set:
6+
PowerPointApi: '1.6'
7+
script:
8+
content: |
9+
$("#get-hyperlinks").on("click", () => tryCatch(getHyperlinks));
10+
11+
async function getHyperlinks() {
12+
// Gets the hyperlinks found in the first selected slide.
13+
await PowerPoint.run(async (context) => {
14+
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
15+
const hyperlinks: PowerPoint.HyperlinkCollection = slide.hyperlinks.load("address,screenTip");
16+
const hyperlinksCount = hyperlinks.getCount();
17+
await context.sync();
18+
19+
console.log(`${hyperlinksCount.value} hyperlinks found in first selected slide:`);
20+
for (let link of hyperlinks.items) {
21+
console.log(`Address: "${link.address}" (Screen tip: "${link.screenTip}")`);
22+
}
23+
});
24+
}
25+
26+
/** Default helper for invoking an action and handling errors. */
27+
async function tryCatch(callback) {
28+
try {
29+
await callback();
30+
} catch (error) {
31+
// Note: In a production add-in, you'd want to notify the user through your add-in's UI.
32+
console.error(error);
33+
}
34+
}
35+
language: typescript
36+
template:
37+
content: |-
38+
<section class="ms-font-m">
39+
<p class="ms-font-m">Demonstrates how to get the hyperlinks located in a slide.</p>
40+
</section>
41+
42+
<section class="samples ms-font-m">
43+
<h3>Try it out</h3>
44+
<p>First, add at least one hyperlink to a slide then select at least one slide.</p>
45+
<button id="get-hyperlinks" class="ms-Button">
46+
<span class="ms-Button-label">Get hyperlinks</span>
47+
</button>
48+
</section>
49+
language: html
50+
style:
51+
content: |-
52+
section.samples {
53+
margin-top: 20px;
54+
}
55+
56+
section.samples .ms-Button, section.setup .ms-Button {
57+
display: block;
58+
margin-bottom: 5px;
59+
margin-left: 20px;
60+
min-width: 80px;
61+
}
62+
language: css
63+
libraries: |
64+
https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
65+
@types/office-js-preview
66+
67+
[email protected]/dist/css/fabric.min.css
68+
[email protected]/dist/css/fabric.components.min.css
69+
70+
[email protected]/client/core.min.js
71+
@types/core-js
72+
73+
74+
126 Bytes
Binary file not shown.

snippet-extractor-output/snippets.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14141,6 +14141,44 @@
1414114141

1414214142
await context.sync();
1414314143
});
14144+
'PowerPoint.Hyperlink:class':
14145+
- >-
14146+
// Link to full sample:
14147+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/manage-hyperlinks.yaml
14148+
14149+
14150+
// Gets the hyperlinks found in the first selected slide.
14151+
14152+
await PowerPoint.run(async (context) => {
14153+
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
14154+
const hyperlinks: PowerPoint.HyperlinkCollection = slide.hyperlinks.load("address,screenTip");
14155+
const hyperlinksCount = hyperlinks.getCount();
14156+
await context.sync();
14157+
14158+
console.log(`${hyperlinksCount.value} hyperlinks found in first selected slide:`);
14159+
for (let link of hyperlinks.items) {
14160+
console.log(`Address: "${link.address}" (Screen tip: "${link.screenTip}")`);
14161+
}
14162+
});
14163+
'PowerPoint.HyperlinkCollection:class':
14164+
- >-
14165+
// Link to full sample:
14166+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/manage-hyperlinks.yaml
14167+
14168+
14169+
// Gets the hyperlinks found in the first selected slide.
14170+
14171+
await PowerPoint.run(async (context) => {
14172+
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
14173+
const hyperlinks: PowerPoint.HyperlinkCollection = slide.hyperlinks.load("address,screenTip");
14174+
const hyperlinksCount = hyperlinks.getCount();
14175+
await context.sync();
14176+
14177+
console.log(`${hyperlinksCount.value} hyperlinks found in first selected slide:`);
14178+
for (let link of hyperlinks.items) {
14179+
console.log(`Address: "${link.address}" (Screen tip: "${link.screenTip}")`);
14180+
}
14181+
});
1414414182
'PowerPoint.InsertSlideFormatting:enum':
1414514183
- >-
1414614184
// Link to full sample:

view-prod/powerpoint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"powerpoint-create-presentation": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/document/create-presentation.yaml",
66
"powerpoint-basics-insert-image": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/images/insert-image.yaml",
77
"powerpoint-basics-insert-svg": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/images/insert-svg.yaml",
8+
"powerpoint-manage-hyperlinks": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/manage-hyperlinks.yaml",
89
"powerpoint-scenarios-searches-wikipedia-api": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/scenarios/searches-wikipedia-api.yaml",
910
"powerpoint-shapes-get-set-shapes": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml",
1011
"powerpoint-shapes-get-shapes-by-type": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shapes-by-type.yaml",

view/powerpoint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"powerpoint-create-presentation": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/document/create-presentation.yaml",
66
"powerpoint-basics-insert-image": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/images/insert-image.yaml",
77
"powerpoint-basics-insert-svg": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/images/insert-svg.yaml",
8+
"powerpoint-manage-hyperlinks": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/preview-apis/manage-hyperlinks.yaml",
89
"powerpoint-scenarios-searches-wikipedia-api": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/scenarios/searches-wikipedia-api.yaml",
910
"powerpoint-shapes-get-set-shapes": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/shapes/get-set-shapes.yaml",
1011
"powerpoint-shapes-get-shapes-by-type": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/shapes/get-shapes-by-type.yaml",

0 commit comments

Comments
 (0)