Created
December 3, 2020 02:33
-
-
Save Rick-Kirkham/f65eb07519822c65601298e5c489e3f8 to your computer and use it in GitHub Desktop.
Deletes a slide from the presentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Delete slide | |
description: Deletes a slide from the presentation | |
host: POWERPOINT | |
api_set: {} | |
script: | |
content: > | |
$("#insert-all-slides").click(() => tryCatch(insertAllSlides)); | |
$("#insert-after-target-slide").click(() => | |
tryCatch(insertAfterSelectedSlide)); | |
$("#file").change(() => tryCatch(storeFileAsBase64)); | |
let chosenFileBase64; | |
async function storeFileAsBase64() { | |
const reader = new FileReader(); | |
reader.onload = async (event) => { | |
// Strip off the metadata before the base64-encoded string | |
const startIndex = reader.result.toString().indexOf("base64,"); | |
const copyBase64 = reader.result.toString().substr(startIndex + 7); | |
chosenFileBase64 = copyBase64; | |
}; | |
// Read in the file and store a base64-encoded copy as the reader.result | |
// property. This also triggers the onload event. | |
const myFile = document.getElementById("file") as HTMLInputElement; | |
reader.readAsDataURL(myFile.files[0]); | |
} | |
async function insertAllSlides() { | |
await PowerPoint.run(async function(context) { | |
context.presentation.insertSlidesFromBase64(chosenFileBase64); | |
await context.sync(); | |
}); | |
} | |
async function insertAfterSelectedSlide() { | |
await PowerPoint.run(async function(context) { | |
const selectedSlideID = await getSelectedSlideID(); | |
context.presentation.insertSlidesFromBase64(chosenFileBase64, { | |
formatting: PowerPoint.InsertSlideFormatting.useDestinationTheme, | |
targetSlideId: selectedSlideID + "#", | |
sourceSlideIds: ["258#", "260#"] | |
}); | |
await context.sync(); | |
}); | |
} | |
function getSelectedSlideID() { | |
// Wrap a call of one of the Common APIs in a Promise-returning | |
// function, so that it can be easily called within a run() method | |
// of an application-specific API. | |
return new OfficeExtension.Promise<string>(function(resolve, reject) { | |
Office.context.document.getSelectedDataAsync(Office.CoercionType.SlideRange, function(asyncResult) { | |
try { | |
if (asyncResult.status === Office.AsyncResultStatus.Failed) { | |
reject(console.error(asyncResult.error.message)); | |
} else { | |
resolve(asyncResult.value.slides[0].id); | |
} | |
} catch (error) { | |
reject(console.log(error)); | |
} | |
}); | |
}); | |
} | |
/** 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\">\n\t<p>This sample shows how to insert slides from another presentation into the currrent presentation.</p>\n</section>\n\n<section class=\"samples ms-font-m\">\n\t<h3>Try it out</h3>\n\t<p>\n\t\t<ol>\n\t\t\t<li>Open this add-in in a brand new presentation.</li>\n\t\t\t<li>Add at least 2 slides to the presentation.</li>\n\t\t\t<li>Next, select a PowerPoint presentation from which to insert slides.</li>\n\t\t</ol>\n\t\t<form>\n\t\t\t<input type=\"file\" id=\"file\" />\n </form>\n\t</p>\n\t<p>Press <b>Insert all slides</b> to insert all the slides from the source presentation at the beginning of the\n\t\tcurrent presentation using the source formatting.</p>\n\t<button id=\"insert-all-slides\" class=\"ms-Button\">\n\t\t\t<span class=\"ms-Button-label\">Insert all slides</span>\n\t</button>\n\t<p>Press <b>Insert after selected slide</b> to insert the slides from the source presentation just after the selected\n\t\tslide of the current presentation, with the destination formatting.</p>\n\t<button id=\"insert-after-target-slide\" class=\"ms-Button\">\n\t\t\t<span class=\"ms-Button-label\">Insert after selected slide</span>\n\t</button>\n\t<p><b>To undo an insertion, click anywhere on the presentation and press Ctrl-Z.</b></p>\n</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 | |
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css | |
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css | |
core-js@2.4.1/client/core.min.js | |
@types/core-js | |
jquery@3.1.1 | |
@types/jquery@3.3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Insert slides from other presentation | |
description: Inserts slides from another PowerPoint file into the current presentation. | |
host: POWERPOINT | |
api_set: {} | |
script: | |
content: > | |
$("#insert-all-slides").click(() => tryCatch(insertAllSlides)); | |
$("#insert-after-target-slide").click(() => | |
tryCatch(insertAfterSelectedSlide)); | |
$("#file").change(() => tryCatch(storeFileAsBase64)); | |
let chosenFileBase64; | |
async function storeFileAsBase64() { | |
const reader = new FileReader(); | |
reader.onload = async (event) => { | |
// Strip off the metadata before the base64-encoded string | |
const startIndex = reader.result.toString().indexOf("base64,"); | |
const copyBase64 = reader.result.toString().substr(startIndex + 7); | |
chosenFileBase64 = copyBase64; | |
}; | |
// Read in the file and store a base64-encoded copy as the reader.result | |
// property. This also triggers the onload event. | |
const myFile = document.getElementById("file") as HTMLInputElement; | |
reader.readAsDataURL(myFile.files[0]); | |
} | |
async function insertAllSlides() { | |
await PowerPoint.run(async function(context) { | |
context.presentation.insertSlidesFromBase64(chosenFileBase64); | |
await context.sync(); | |
}); | |
} | |
async function insertAfterSelectedSlide() { | |
await PowerPoint.run(async function(context) { | |
const selectedSlideID = await getSelectedSlideID(); | |
context.presentation.insertSlidesFromBase64(chosenFileBase64, { | |
formatting: PowerPoint.InsertSlideFormatting.useDestinationTheme, | |
targetSlideId: selectedSlideID + "#", | |
sourceSlideIds: ["258#", "260#"] | |
}); | |
await context.sync(); | |
}); | |
} | |
function getSelectedSlideID() { | |
// Wrap a call of one of the Common APIs in a Promise-returning | |
// function, so that it can be easily called within a run() method | |
// of an application-specific API. | |
return new OfficeExtension.Promise<string>(function(resolve, reject) { | |
Office.context.document.getSelectedDataAsync(Office.CoercionType.SlideRange, function(asyncResult) { | |
try { | |
if (asyncResult.status === Office.AsyncResultStatus.Failed) { | |
reject(console.error(asyncResult.error.message)); | |
} else { | |
resolve(asyncResult.value.slides[0].id); | |
} | |
} catch (error) { | |
reject(console.log(error)); | |
} | |
}); | |
}); | |
} | |
/** 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\">\n\t<p>This sample shows how to insert slides from another presentation into the currrent presentation.</p>\n</section>\n\n<section class=\"samples ms-font-m\">\n\t<h3>Try it out</h3>\n\t<p>\n\t\t<ol>\n\t\t\t<li>Open this add-in in a brand new presentation.</li>\n\t\t\t<li>Add at least 2 slides to the presentation.</li>\n\t\t\t<li>Next, select a PowerPoint presentation from which to insert slides.</li>\n\t\t</ol>\n\t\t<form>\n\t\t\t<input type=\"file\" id=\"file\" />\n </form>\n\t</p>\n\t<p>Press <b>Insert all slides</b> to insert all the slides from the source presentation at the beginning of the\n\t\tcurrent presentation using the source formatting.</p>\n\t<button id=\"insert-all-slides\" class=\"ms-Button\">\n\t\t\t<span class=\"ms-Button-label\">Insert all slides</span>\n\t</button>\n\t<p>Press <b>Insert after selected slide</b> to insert the slides from the source presentation just after the selected\n\t\tslide of the current presentation, with the destination formatting.</p>\n\t<button id=\"insert-after-target-slide\" class=\"ms-Button\">\n\t\t\t<span class=\"ms-Button-label\">Insert after selected slide</span>\n\t</button>\n\t<p><b>To undo an insertion, click anywhere on the presentation and press Ctrl-Z.</b></p>\n</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 | |
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css | |
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css | |
core-js@2.4.1/client/core.min.js | |
@types/core-js | |
jquery@3.1.1 | |
@types/jquery@3.3.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment