I am using the code below to apply a custom paragraph style called "Table: Body Text" to text in tables, but it doesn't apply the style to all the selected text. For example, if I only select a column, and click my style button, it only applies the style to the last row in the selected column not all the rows in the selected column. Seems a bit random.
A couple of weeks ago, it was only applying the style to one of the many rows I had selected, but that seems to have resolved - perhaps with exiting out and going back in. So the column is the main issue now.
For example if I want to select three cells in the first column to apply a Row Heading style, it will only apply the style to the last cell in the set of selected rows in the first column. Same with wanting to apply a Table Bullet style to the last column - it won't do it except one by one.
Apologies, I just don't know enough about the Javascript API and how Javascript works to know where to begin to get this code to do what I need it to do specifically.
Thanks!
function applytablebodytextstyle() {
Word.run(function (context) {
var pars = context.document.getSelection().paragraphs;
pars.load();
return context.sync().then(function () {
for (var i = 0; i < pars.items.length; i++) {
pars.items[i].style = "Table: Body Text";
}
return context.sync();
})
}) //needed for Stack overflow
.catch(function (error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
}