forked from OfficeDev/outlook-add-in-command-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InsertText.js
34 lines (28 loc) · 1.1 KB
/
InsertText.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE.txt in the project root for license information.
/// <reference path="../App.js" />
(function () {
"use strict";
// The Office initialize function must be run each time a new page is loaded
Office.initialize = function (reason) {
$(document).ready(function () {
app.initialize();
$('#insertText').click(insertText);
});
};
function insertText() {
var textToInsert = $('#textToInsert').val();
// Insert as plain text (CoercionType.Text)
Office.context.mailbox.item.body.setSelectedDataAsync(
textToInsert,
{ coercionType: Office.CoercionType.Text },
function (asyncResult) {
// Display the result to the user
if (asyncResult.status == Office.AsyncResultStatus.Succeeded) {
app.showNotification("Success", "\"" + textToInsert + "\" inserted successfully.");
}
else {
app.showNotification("Error", "Failed to insert \"" + textToInsert + "\": " + asyncResult.error.message);
}
});
}
})();