Skip to content

Instantly share code, notes, and snippets.

@jipyua
Created January 30, 2024 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jipyua/87386bae781b94fa0c7e86e4ef7a7919 to your computer and use it in GitHub Desktop.
Save jipyua/87386bae781b94fa0c7e86e4ef7a7919 to your computer and use it in GitHub Desktop.
Performs a basic Word API call using TypeScript.
name: citation item
description: Performs a basic Word API call using TypeScript.
host: WORD
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
async function run() {
// Gets the current selection and changes the font color to red.
await Word.run(async (context) => {
const range = context.document.getSelection();
range.font.color = "red";
range.load("text");
await context.sync();
console.log(`The selected text was "${range.text}".`);
});
}
/** 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 This sample executes a code snippet that prints the selected text to the console. Make sure to enter and select text before clicking \"Print selection\".\n</section>\n<button id=\"run\" class=\"ms-Button\">\n <span class=\"ms-Button-label\">Print selection</span>\n</button>\n<div style=\"display: flex; align-items: flex-start;\">\n\t<input type=\"checkbox\" style=\"margin-right: 15px; margin-top:18px\">\n\t<div>\n\t\t<p style=\"font-size:15px;\">\n\t\t\t<strong>Inverse molecular design using machine learning:Generative models for matter engineering</strong>\n\t\t</p>\n\t\t<p style=\"font-size:12px;\">Sanchez-Lengeling B, Aspuru-Guzik A</p>\n\t\t<p style=\"font-size:12px;\"><em>Science (2018) 361(6400) 360-365</em></p>\n\t</div>\n</div>\n<div style=\"display: flex; align-items: flex-start;\">\n\t<input type=\"checkbox\" style=\"margin-right: 15px; margin-top:18px\">\n\t<div>\n\t\t<p style=\"font-size:15px;\">\n\t\t\t<strong>Explainable AI: Beware of Inmates Running the Asylum Or: How I Learnt to Stop Worrying and Love the Social and Behavioural Sciences</strong>\n\t\t</p>\n\t\t<p style=\"font-size:12px;\">Zhong B, Luo W, […] Li Y</p>\n\t\t<p style=\"font-size:12px\"><em>International Journal of Biological Sciences (2020) 16(10)</em></p>\n\t</div>\n</div>\n<div style=\"display: flex; align-items: flex-start;\">\n\t<input type=\"checkbox\" style=\"margin-right: 15px; margin-top:18px\">\n\t<div>\n\t\t<p style=\"font-size:15px;\">\n\t\t\t<strong>Deep neural networks for acoustic modeling in speech recognition: The shared views of four research groups</strong>\n\t\t</p>\n\t\t<p style=\"font-size:12px;\">Hinton G, Deng L, […] Kingsbury B</p>\n\t\t<p style=\"font-size:12px\"><em>IEEE Signal Processing Magazine (2012) 29(6) 82-97</em></p>\n\t</div>\n</div>"
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