How to get footnote number?

Peter Henry 0 Reputation points
2023-12-12T17:15:00.0466667+00:00

In the C# api there is an easy way to get the footnote index. How do I do it in the Javascript version?

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
1,063 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Azar 29,520 Reputation points MVP Volunteer Moderator
    2023-12-12T17:44:18.65+00:00

    Hi Peter Henry

    This is possible through the paragraphs property. You can iterate through the paragraphs and check if each paragraph is part of a footnote, then extract the index.

    // Run a batch operation to access the document Word.run(async (context) => {     // Get the paragraphs in the document     let paragraphs = context.document.body.paragraphs;          // Load the paragraphs and footnotes     paragraphs.load("items,items/footnoteOrNull");      await context.sync();      // Iterate through the paragraphs and check for footnotes     paragraphs.items.forEach((paragraph, index) => {         let footnote = paragraph.footnoteOrNull;         if (footnote.isNullObject) {             // The paragraph is not part of a footnote         } else {             // The paragraph is part of a footnote             console.log("Paragraph at index " + index + " is part of footnote with ID: " + footnote.id);         }     }); }); 
    
    
    

    Kindly accept the answer if this helps thanks much.

    0 comments No comments

  2. HuaweiChim-5458 0 Reputation points
    2023-12-12T18:34:01.31+00:00

    // Run a batch operation to access the document Word.run(async (context) => { // Get the paragraphs in the document let paragraphs = context.document.body.paragraphs; // Load the paragraphs and footnotes paragraphs.load("items,items/footnoteOrNull"); await context.sync(); // Iterate through the paragraphs and check for footnotes paragraphs.items.forEach((paragraph, index) => { let footnote = paragraph.footnoteOrNull; if (footnote.isNullObject) { // The paragraph is not part of a footnote } else { // The paragraph is part of a footnote console.log("Paragraph at index " + index + " is part of footnote with ID: " + footnote.id); } }); });_

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.