Skip to content
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
122 changes: 121 additions & 1 deletion samples/powerpoint/hyperlinks/manage-hyperlinks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ script:
.addEventListener("click", () => tryCatch(setHyperlinkOnTextRange));
document.getElementById("set-hyperlink-on-shape").addEventListener("click", () => tryCatch(setHyperlinkOnShape));
document.getElementById("get-hyperlinks").addEventListener("click", () => tryCatch(getHyperlinks));
document
.getElementById("update-text-range-hyperlink")
.addEventListener("click", () => tryCatch(updateHyperlinkOnTextRange));
document.getElementById("update-shape-hyperlink").addEventListener("click", () => tryCatch(updateHyperlinkOnShape));
document
.getElementById("delete-text-range-hyperlink")
.addEventListener("click", () => tryCatch(deleteHyperlinkFromTextRange));
document.getElementById("delete-shape-hyperlink").addEventListener("click", () => tryCatch(deleteHyperlinkFromShape));
document.getElementById("setup").addEventListener("click", () => tryCatch(setup));

async function setHyperlinkOnTextRange() {
Expand All @@ -27,7 +35,9 @@ script:
try {
await context.sync();
} catch {
console.warn("Confirm that you have at least one slide and you've selected a contiguous range of text on the active slide.");
console.warn(
"Confirm that you have at least one slide and you've selected a contiguous range of text on the active slide.",
);
return;
}

Expand Down Expand Up @@ -78,6 +88,104 @@ script:
});
}

async function updateHyperlinkOnTextRange() {
// Updates the first hyperlink found in the text range selection on the current slide.
await PowerPoint.run(async (context) => {
const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange().load("text");
let hyperlink: PowerPoint.Hyperlink = textRange.hyperlinks.getItemAt(0).load("address,screenTip");
try {
await context.sync();
} catch {
console.warn(
"Confirm that you have at least one slide and you've selected a contiguous range of text containing at least one hyperlink on the active slide.",
);
return;
}

console.log(
`About to update first link "${hyperlink.address}" (screen tip: "${hyperlink.screenTip}") found in the selected text "${textRange.text}"...`,
);

hyperlink.address = "https://www.microsoft.com";
hyperlink.screenTip = "Updated screen tip of link on text range";

console.log(
`Updated first link found in the selected text "${textRange.text}" to "${hyperlink.address}" (screen tip: "${hyperlink.screenTip}").`,
);
});
}

async function updateHyperlinkOnShape() {
// Updates the hyperlink on the first selected shape on the current slide.
await PowerPoint.run(async (context) => {
const shape: PowerPoint.Shape = context.presentation.getSelectedShapes().getItemAt(0).load("type");
const hyperlinkAddOptions: PowerPoint.HyperlinkAddOptions = {
address: "https://www.microsoft.com",
screenTip: "Updated screen tip of link on shape",
};
const hyperlink: PowerPoint.Hyperlink = shape.setHyperlink(hyperlinkAddOptions).load("address,screenTip");
try {
await context.sync();
} catch {
console.warn("Confirm that you have at least one slide and you've selected a shape on the active slide.");
return;
}

console.log(
`Updated link on the selected ${shape.type} shape to "${hyperlink.address}" (screen tip: "${hyperlink.screenTip}").`,
);
});
}

async function deleteHyperlinkFromTextRange() {
// Deletes the first hyperlink found in the selected text on the current slide.
await PowerPoint.run(async (context) => {
const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange().load("text");
let hyperlink: PowerPoint.Hyperlink = textRange.hyperlinks.getItemAt(0).load("address,screenTip");
try {
await context.sync();
} catch {
console.warn(
"Confirm that you have at least one slide and you've selected a contiguous range of text containing at least one hyperlink on the active slide.",
);
return;
}

console.log(
`About to delete first link "${hyperlink.address}" (screen tip: "${hyperlink.screenTip}") found in the selected text "${textRange.text}".`,
);

hyperlink.delete();

console.log(`Deleted first link found in the selected text "${textRange.text}".`);
});
}

async function deleteHyperlinkFromShape() {
// Deletes the hyperlink from the first selected shape on the current slide.
await PowerPoint.run(async (context) => {
const shape: PowerPoint.Shape = context.presentation.getSelectedShapes().getItemAt(0).load("type");

// Get an object representing the hyperlink on the selected shape. No need to set any properties since it's going to be deleted.
const hyperlink: PowerPoint.Hyperlink = shape.setHyperlink();

try {
await context.sync();
} catch {
console.warn("Confirm that you have at least one slide and you've selected a shape on the active slide.");
return;
}

console.log(
`About to delete link from the selected ${shape.type} shape.`,
);

hyperlink.delete();

console.log("Deleted link from the selected shape.");
});
}

async function setup() {
await PowerPoint.run(async (context) => {
// Adds a new slide with two shapes.
Expand Down Expand Up @@ -144,6 +252,18 @@ template:
<button id="set-hyperlink-on-shape">Set hyperlink on shape</button>
</p>
<button id="get-hyperlinks">Get hyperlinks</button>
<p>Select hyperlinked text on the slide then click <b>Update hyperlink on text</b> button
<button id="update-text-range-hyperlink">Update hyperlink on text</button>
</p>
<p>Select hyperlinked shape on the slide then click <b>Update hyperlink on shape</b> button
<button id="update-shape-hyperlink">Update hyperlink on shape</button>
</p>
<p>Select hyperlinked text on the slide then click <b>Delete hyperlink from text</b> button
<button id="delete-text-range-hyperlink">Delete hyperlink from text</button>
</p>
<p>Select hyperlinked shape on the slide then click <b>Delete hyperlink from shape</b> button
<button id="delete-shape-hyperlink">Delete hyperlink from shape</button>
<p>
</section>
language: html
style:
Expand Down
Binary file modified snippet-extractor-metadata/excel.xlsx
Binary file not shown.
Binary file modified snippet-extractor-metadata/powerpoint.xlsx
Binary file not shown.
63 changes: 60 additions & 3 deletions snippet-extractor-output/snippets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8872,7 +8872,7 @@ Excel.WorksheetChangedEventArgs#triggerSource:member:
}
});
}
Excel.WorksheetMovedEventArgs:event:
Excel.WorksheetMovedEventArgs:interface:
- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/30-events/events-workbook-and-worksheet-collection.yaml
Expand All @@ -8887,7 +8887,7 @@ Excel.WorksheetMovedEventArgs:event:
console.log(` Event source: ${event.source}`);
});
}
Excel.WorksheetNameChangedEventArgs:event:
Excel.WorksheetNameChangedEventArgs:interface:
- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/30-events/events-worksheet.yaml
Expand Down Expand Up @@ -16801,6 +16801,35 @@ PowerPoint.Hyperlink:class:
console.log(`Address: "${link.address}" (screen tip: "${link.screenTip}").`);
}
});
PowerPoint.Hyperlink#delete:member(1):
- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/hyperlinks/manage-hyperlinks.yaml


// Deletes the first hyperlink found in the selected text on the current
slide.

await PowerPoint.run(async (context) => {
const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange().load("text");
let hyperlink: PowerPoint.Hyperlink = textRange.hyperlinks.getItemAt(0).load("address,screenTip");
try {
await context.sync();
} catch {
console.warn(
"Confirm that you have at least one slide and you've selected a contiguous range of text containing at least one hyperlink on the active slide.",
);
return;
}

console.log(
`About to delete first link "${hyperlink.address}" (screen tip: "${hyperlink.screenTip}") found in the selected text "${textRange.text}".`,
);

hyperlink.delete();

console.log(`Deleted first link found in the selected text "${textRange.text}".`);
});
PowerPoint.HyperlinkAddOptions:interface:
- >-
// Link to full sample:
Expand All @@ -16821,7 +16850,9 @@ PowerPoint.HyperlinkAddOptions:interface:
try {
await context.sync();
} catch {
console.warn("Confirm that you have at least one slide and you've selected a contiguous range of text on the active slide.");
console.warn(
"Confirm that you have at least one slide and you've selected a contiguous range of text on the active slide.",
);
return;
}

Expand Down Expand Up @@ -17444,6 +17475,32 @@ PowerPoint.Shape#getTable:member(1):
} else console.log("Selected shape isn't table.");
} else console.log("No shape selected.");
});
PowerPoint.Shape#setHyperlink:member(1):
- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/hyperlinks/manage-hyperlinks.yaml


// Updates the hyperlink on the first selected shape on the current slide.

await PowerPoint.run(async (context) => {
const shape: PowerPoint.Shape = context.presentation.getSelectedShapes().getItemAt(0).load("type");
const hyperlinkAddOptions: PowerPoint.HyperlinkAddOptions = {
address: "https://www.microsoft.com",
screenTip: "Updated screen tip of link on shape",
};
const hyperlink: PowerPoint.Hyperlink = shape.setHyperlink(hyperlinkAddOptions).load("address,screenTip");
try {
await context.sync();
} catch {
console.warn("Confirm that you have at least one slide and you've selected a shape on the active slide.");
return;
}

console.log(
`Updated link on the selected ${shape.type} shape to "${hyperlink.address}" (screen tip: "${hyperlink.screenTip}").`,
);
});
PowerPoint.Shape#setZOrder:member(1):
- >-
// Link to full sample:
Expand Down