Uppercase font in Word JS API

Sebastian123 26 Reputation points
2022-03-26T05:43:25.457+00:00

I am looking to apply sentence case, upper case etc to text using the word JS API. The script is as below.

Is there a property to change the font case to capitals etc? I am not sure how to apply toUpperCase() to this script, but I do not think this would be of use because it would remove the underlying capitalisation, making it impossible to return back to its previous case.

Could you please assist?

async function headingOne() {
await Word.run(async (context) => {
let paragraphs = context.document.getSelection().paragraphs;
context.load(paragraphs, 'style, font, text');
await context.sync();
for (i = 0; i < paragraphs.items.length; i++) {
paragraphs.items[i].spaceBefore = 12;
paragraphs.items[i].spaceAfter = 9;
paragraphs.items[i].font.name = 'Times New Roman';
paragraphs.items[i].font.size = 12;
paragraphs.items[i].font.bold = true;
paragraphs.items[i].font.italic = false;
paragraphs.items[i].text.toUpperCase();
}
await context.sync();
});
}

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
867 questions
0 comments No comments
{count} votes