Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a new snippet from a blank template.
id: a3b78c4e-1b4b-45ee-893b-9bc7abcf0506
name: Loading Ranges
description: Create a new snippet from a blank template.
host: WORD
api_set: {}
script:
content: |
$("#run").click(loadCombo);
function loadCombo() {
Word.run(function (context) {
var rangesAr = [];
var currentlySelectedIndex = 0;
var myRanges = context.document.body.search("Word");
context.load(myRanges, { expand: 'font' });
return context.sync()
.then(function () {
var myCombo = document.getElementById("FoundRanges");
for (var i = 0; i < myRanges.items.length; i++) {
var myItem = document.createElement("option");
myItem.text = myRanges.items[i].text
myCombo.add(myItem);
var newRange = myRanges.items[i].getRange();
rangesAr.push(newRange);
context.trackedObjects.add(newRange);
}
$('#FoundRanges').change(function () {
rangesAr[this.selectedIndex].font.bold = true;
currentlySelectedIndex = this.selectedIndex;
return context.sync()
.catch(function (e) {
console.og(e.message);
})
});
return context.sync()
})
}).catch(function (e) {
console.log(e.message)
})
}
language: typescript
template:
content: "<section class=\"ms-font-m\">\n\tThis sample shows how to use tracked objects. Searches for the test \"Word\", an array of ranges is created and later accessed via the combo.\n</section>\n<button id=\"run\" class=\"ms-Button\">\n <span class=\"ms-Button-label\">Load Combo</span>\n</button>\n\n<select id=\"FoundRanges\">\n </select>"
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
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.min.js
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.d.ts
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
You can’t perform that action at this time.