Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PowerPoint] Add manage-hyperlinks #936

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions playlists-prod/powerpoint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/images/insert-svg.yaml
group: Images
api_set: {}
- id: powerpoint-manage-hyperlinks
name: Get hyperlinks
fileName: manage-hyperlinks.yaml
description: Gets the hyperlinks found in a slide.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/manage-hyperlinks.yaml
group: Preview APIs
api_set:
PowerPointApi: '1.6'
- id: powerpoint-scenarios-searches-wikipedia-api
name: Search Wikipedia
fileName: searches-wikipedia-api.yaml
Expand Down
9 changes: 9 additions & 0 deletions playlists/powerpoint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/images/insert-svg.yaml
group: Images
api_set: {}
- id: powerpoint-manage-hyperlinks
name: Get hyperlinks
fileName: manage-hyperlinks.yaml
description: Gets the hyperlinks found in a slide.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/preview-apis/manage-hyperlinks.yaml
group: Preview APIs
api_set:
PowerPointApi: '1.6'
- id: powerpoint-scenarios-searches-wikipedia-api
name: Search Wikipedia
fileName: searches-wikipedia-api.yaml
Expand Down
74 changes: 74 additions & 0 deletions samples/powerpoint/preview-apis/manage-hyperlinks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
id: powerpoint-manage-hyperlinks
name: Get hyperlinks
description: Gets the hyperlinks found in a slide.
host: POWERPOINT
api_set:
PowerPointApi: '1.6'
script:
content: |
$("#get-hyperlinks").on("click", () => tryCatch(getHyperlinks));

async function getHyperlinks() {
// Gets the hyperlinks found in the first selected slide.
await PowerPoint.run(async (context) => {
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
const hyperlinks: PowerPoint.HyperlinkCollection = slide.hyperlinks.load("address,screenTip");
const hyperlinksCount = hyperlinks.getCount();
await context.sync();

console.log(`${hyperlinksCount.value} hyperlinks found in first selected slide:`);
for (let link of hyperlinks.items) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't actually know you could do a foreach loop like this in JS. Very cool!

console.log(`Address: "${link.address}" (Screen tip: "${link.screenTip}")`);
}
});
}

/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
try {
await callback();
} catch (error) {
// Note: In a production add-in, you'd want to notify the user through your add-in's UI.
console.error(error);
}
}
language: typescript
template:
content: |-
<section class="ms-font-m">
<p class="ms-font-m">Demonstrates how to get the hyperlinks located in a slide.</p>
</section>

<section class="samples ms-font-m">
<h3>Try it out</h3>
<p>First, add at least one hyperlink to a slide then select at least one slide.</p>
<button id="get-hyperlinks" class="ms-Button">
<span class="ms-Button-label">Get hyperlinks</span>
</button>
</section>
language: html
style:
content: |-
section.samples {
margin-top: 20px;
}

section.samples .ms-Button, section.setup .ms-Button {
display: block;
margin-bottom: 5px;
margin-left: 20px;
min-width: 80px;
}
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
@types/office-js-preview

[email protected]/dist/css/fabric.min.css
[email protected]/dist/css/fabric.components.min.css

[email protected]/client/core.min.js
@types/core-js

[email protected]
@types/[email protected]
Binary file modified snippet-extractor-metadata/powerpoint.xlsx
Binary file not shown.
38 changes: 38 additions & 0 deletions snippet-extractor-output/snippets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14141,6 +14141,44 @@

await context.sync();
});
'PowerPoint.Hyperlink:class':
- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/manage-hyperlinks.yaml


// Gets the hyperlinks found in the first selected slide.

await PowerPoint.run(async (context) => {
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
const hyperlinks: PowerPoint.HyperlinkCollection = slide.hyperlinks.load("address,screenTip");
const hyperlinksCount = hyperlinks.getCount();
await context.sync();

console.log(`${hyperlinksCount.value} hyperlinks found in first selected slide:`);
for (let link of hyperlinks.items) {
console.log(`Address: "${link.address}" (Screen tip: "${link.screenTip}")`);
}
});
'PowerPoint.HyperlinkCollection:class':
- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/manage-hyperlinks.yaml


// Gets the hyperlinks found in the first selected slide.

await PowerPoint.run(async (context) => {
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
const hyperlinks: PowerPoint.HyperlinkCollection = slide.hyperlinks.load("address,screenTip");
const hyperlinksCount = hyperlinks.getCount();
await context.sync();

console.log(`${hyperlinksCount.value} hyperlinks found in first selected slide:`);
for (let link of hyperlinks.items) {
console.log(`Address: "${link.address}" (Screen tip: "${link.screenTip}")`);
}
});
'PowerPoint.InsertSlideFormatting:enum':
- >-
// Link to full sample:
Expand Down
1 change: 1 addition & 0 deletions view-prod/powerpoint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"powerpoint-create-presentation": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/document/create-presentation.yaml",
"powerpoint-basics-insert-image": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/images/insert-image.yaml",
"powerpoint-basics-insert-svg": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/images/insert-svg.yaml",
"powerpoint-manage-hyperlinks": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/manage-hyperlinks.yaml",
"powerpoint-scenarios-searches-wikipedia-api": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/scenarios/searches-wikipedia-api.yaml",
"powerpoint-shapes-get-set-shapes": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml",
"powerpoint-shapes-get-shapes-by-type": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shapes-by-type.yaml",
Expand Down
1 change: 1 addition & 0 deletions view/powerpoint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"powerpoint-create-presentation": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/document/create-presentation.yaml",
"powerpoint-basics-insert-image": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/images/insert-image.yaml",
"powerpoint-basics-insert-svg": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/images/insert-svg.yaml",
"powerpoint-manage-hyperlinks": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/preview-apis/manage-hyperlinks.yaml",
"powerpoint-scenarios-searches-wikipedia-api": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/scenarios/searches-wikipedia-api.yaml",
"powerpoint-shapes-get-set-shapes": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/shapes/get-set-shapes.yaml",
"powerpoint-shapes-get-shapes-by-type": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/shapes/get-shapes-by-type.yaml",
Expand Down