A collection of samples for the Add-in Playground
- Fork this repo
- Add samples using the instructions below
- Submit a pull request that Bhargav or Michael Z. will review.
- All snippets must be inside the samples folder.
- The
base folders
such as Excel, Word etc. are all the various broad level categories. - Inside of each
base folder
, there aregroup folders
for the group in which a sample belongs to. - Inside of each
group folder
, there are.yaml
which represent a snippet.
- Create a snippet using the Add-in Playground.
- Click on
Copy to Clipboard
in theShare
menu. - Fill in the
author
,name
,description
,source
properties if they are empty so that we can generate the playlist correctly. - Add that snippet into the respective folders. Make sure that the snippet file names and folder names are in
kebabcase
.
Basic snippet structure is as follows:
$("#run").click(run);
async function run() {
try {
await Word.run(async (context) => {
let range = context.document.getSelection();
range.font.color = "red";
await context.sync();
});
}
catch (error) {
OfficeHelpers.Utilities.log(error);
}
}
A few style rules to observe:
- Each button-click handler should have its own async function, called "run" if there is only one button on the page -- otherwise, name it as you will.
- Inside the function there shall be a try/catch. In it you will await the
Excel.run
orWord.run
, and useasync/await
inside of the.run
as well. - All HTML IDs should be
all-lower-case-and-hyphenated
. - Unless you are explicitly showing pretty UI, I wouldn't do the popup notification except for one or two samples. It's a lot of HTML & JS code, and it's also not strictly Fabric-y (there is a more "correct" way of doing this with components).
- Strings should be in double-quotes.
- Don't forget the semicolons.