JavaScript - Snippets
let paragraph2 = context.document.body.paragraphs;
paragraph2.load('items');
await context.sync();
let list = paragraph2.items[1].startNewList();
let myFirstItem = list.insertParagraph("My 0 item at start", Word.InsertLocation.start)
list.insertParagraph("My 1 item at end", Word.InsertLocation.end).listItem.level = 3
list.insertParagraph("My 2 item at before", Word.InsertLocation.before)
list.insertParagraph("My 3 item at after", Word.InsertLocation.after)
myFirstItem.delete();
let wordLists = context.document.body.lists
let firstList = wordLists.getFirstOrNullObject();
firstList.setLevelBullet(0, Word.ListBullet.hollow);
firstList.setLevelIndents(0, 50, 20);
Inserts a new list into the document
$("#insert-controls").click(() => tryCatch(insertList));
$("#setup").click(() => tryCatch(setup));
async function insertList() {
await Word.run(async (context) => {
let paragraphs = context.document.body.paragraphs;
paragraphs.load("$none"); // No properties needed.
await context.sync();
var list = paragraphs.items[1].startNewList(); // Indicates new list to be started in the second paragraph.
list.load("$none"); // No properties needed.
await context.sync();
list.insertParagraph("New list item on top of the list", "Start");
let paragraph = list.insertParagraph("New list item at the end of the list (4th level)", "End");
paragraph.listItem.level = 4; // Sets up list level for the lsit item.
list.insertParagraph("New paragraph goes after (not part of the list)", "After");
await context.sync();
});
}
async function setup() {
await Word.run(async (context) => {
context.document.body.clear();
context.document.body.insertParagraph(
"Themes and styles also help keep your document coordinated.",
"Start"
);
context.document.body.insertParagraph(
"Save time in Word with new buttons that show up where you need them.",
"Start"
);
context.document.body.insertParagraph(
"Video provides a powerful way to help you prove your point.",
"Start"
);
context.document.body.paragraphs
.getLast()
.insertText(
"To make your document look professionally produced.",
"Replace"
);
});
}
async function tryCatch(callback) {
try {
await callback();
} catch (error) {
console.error(error);
}
}
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrev