Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
Is there a way of obtaining the set of character styles within a Word document using Java Script?

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

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda