Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

414
Vistas
How to extract page numbers from Word document via add-in built using the Word JavaScript API

in Word via an add-in built using the Word Javascript API, I'm trying to read the page number of each location a string of text appears in the document text. E.g. the word "HELP" appears on pages 2, 6, 10 and 45. How can I read the page number?

A stripped down version of the code I have so far is:

async function run() {
  await Word.run(async (context) => {
    let paragraphs = context.document.body.paragraphs;
    paragraphs.load("text"); // WHAT ELSE NEEDS TO BE LOADED TO ALLOW PAGE NO EXTRACTION?
    await context.sync();
    // loop through document to find text
    paragraphs.items.forEach((item) => {
      let paragraph = item.text.trim();
      if (paragraph.includes("EXAMPLE STRING")) {
        let pageNumber = what_goes_here?;
        console.log("Text found on page: " + pageNumber);
      }
    });
  });
}

This works fine for finding the text string, but I can't work out how to get the page number (pageNumber in the code above).

I've been through the Word API documentation but can't find anything. I can, for example, where the text is in a list extract the list level by loading the "listItemOrNullObject" object and reading the "listString", but I can't see any way to get the page number.

Any ideas? If this isn't available via the standard Word API (as I'm suspecting) has anyone got any workarounds?

I'd like to do this using JS and the Word API (great cross platform support etc.) and not have to use VBA, C# etc.

Thank you!

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Currently there hasn't been such an JS API to return the page number of the selected text. You can post the API request here: https://techcommunity.microsoft.com/t5/microsoft-365-developer-platform/idb-p/Microsoft365DeveloperPlatform

Wenjun

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda