Created
June 27, 2023 19:43
-
-
Save JuaneloJuanelo/913d5712f5b739303e4bd5c2fbfaa4f4 to your computer and use it in GitHub Desktop.
Inserts an SVG image using an XML string.
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: NewAPI | |
description: Inserts an SVG image using an XML string. | |
host: POWERPOINT | |
api_set: {} | |
script: | |
content: > | |
$("#run").click(() => tryCatch(run)); | |
const InsertImageAndCreateBinding: Function = async () => { | |
// Following code established the basic flow of crating an image and a Binding. | |
await PowerPoint.run(async (context) => { | |
const myBase64image = getImageAsBase64(); //obtains base64 representation of the image. | |
const shapes = context.presentation.slides.getItemAt(0).shapes; | |
const shapeOptions: PowerPoint.ShapeAddOptions = { | |
left: 100, | |
top: 300, | |
height: 300, | |
width: 450 | |
}; | |
const image = shapes.addImage(myBase64image, shapeOptions); | |
const myBinding = context.presentation.bindings.addById(image.id,PowerPoint.BindingType.Shape, "GUID") | |
myBinding.addHandler("Powerpoint.Events.BindingDeleted", deleteHandler); | |
await context.sync(); | |
}); | |
}; | |
/** Default helper for invoking an action and handling errors. */ | |
const tryCatch: (callback: Function) => void = async (callback: Function) => | |
{ | |
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); | |
} | |
}; | |
function getImageAsBase64(){ | |
} | |
language: typescript | |
template: | |
content: |- | |
<section class="ms-font-m"> | |
This sample executes a code snippet that adds a text box to the first slide in the presentation. | |
</section> | |
<button id="run" class="ms-Button"> | |
<span class="ms-Button-label">Add text box</span> | |
</button> | |
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/1/hosted/office.js | |
@types/office-js | |
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