I am developping a new addin for Word, with Office.js API.
When I apply "Normal" style with the default User Interface in Word by default it keep all other formating styles in the paragraph (bold, italic, character styles...) and as expected it changes only paragraph style to "Normal"
I am trying to emulate the funcionality of appling style "Normal" to a paragraph Programmatically.
I have this piece of code:
function applyStyleParagraph(styleName) {
Word.run(function(context) {
var pars = context.document.getSelection().paragraphs;
context.load(pars, 'style');
return context.sync().then(function () {
for (var i = 0; i < pars.items.length; i++) {
pars.items[i].style = styleName;
}
return context.sync().then(function () {
console.log('Style: ' + styleName + ' / Style paragraph created');
});
})
}).catch(function(error) {
console.log(error);
if (error instanceof OfficeExtension.Error) {
console.log('Style: ' + styleName +
' / Debug info: ' + JSON.stringify(error.debugInfo));
}
});
}
The result is that all other formatting styles (bold, italic, strike, character styles) are removed.
¿How can I preserve all other formatting styles?
This issue affects to Word online an Word 2016.