Based on:
List/Enumerate all Word Styles (custom & predefined) with Office.JS API
I used the following code to get the styles from a Word 2016 document:
`enter code here`Office.context.document.getSelectedDataAsync( Office.CoercionType.Ooxml, ( result ) => {
let xml = $.parseXML(result.value);
let styles = $(xml).find("w\\:styles");
styles.children().each((index, style) => {
// There must be a more elegant way of doing this:
let styleText = style.innerHTML;
console.log("Index = " + index + " has Style text: " + styleText);
let searchText = 'w:name="';
let startPos = 0;
do {
startPos = styleText.indexOf(searchText);
if (startPos != -1) {
startPos = startPos + searchText.length;
let endPos = styleText.indexOf('"', startPos + 1);
let myStyleName = styleText.substring(startPos, endPos);
console.log("Style name: " + myStyleName);
styleText = styleText.substr(endPos);
}
}
while (startPos != -1);
// console.log("Out of loop");
});
}
);
However, the format of the logged output written to the console seems to differ from the referenced article, so I can't get the style type (character or paragraph) without doing some guesswork. I'm guessing that this is pilot error, so can anybody spot where I'm going wrong. I'd add sample output to this post, but it then exceeds the maximum character count.
Cheers.
Tim