Word-Addin heading detection

12 Views Asked by At

I need to detect the heading in a Word document (using the JavaScript API). This is easy if the document actually contains headings, i.e. paragraphs with style "heading*". But for my application I can't guarantee that headings are set. They might be only optical heading with larger font etc. For this reason Word provides the feature to also automatically detect headings based on the styling. Does anyone know how or if it is possible to access these detected headings programmatically? Doing this detection myself seems tedious.

await Word.run(async (context) => {
        const paragraphs = context.document.body.paragraphs;
        context.load(paragraphs, 'text, style');

        await context.sync();

        paragraphs.items.forEach(paragraph => {
            if (["heading"].some(style => paragraph.style.startsWith(style))) {
                headings.push(paragraph.text);
            }
        });

        await context.sync();
    }).catch(errorHandler);

This is the code for getting the already set headings. I want something similar for the detected ones.

0

There are 0 best solutions below