本文介绍使用Spire.Doc for Java读取Word脚注和尾注的方法,添加脚注、尾注可以参考这篇文章。
测试文档如下,包含脚注及尾注:

读取Word脚注
import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.Footnote;
import com.spire.doc.fields.TextRange;
import java.util.List;
public class ExtractFootnoteAndEndnote {
    public static void main(String[] args) {
        //创建Document实例
        Document doc = new Document();
        doc.loadFromFile("test1.docx");
        //获取文档中的所有脚注
       List footNotes = doc.getFootnotes();
       //实例化String类型变量
       String str = "";
       //遍历脚注
        for (Footnote footNote :footNotes) {
            //遍历脚注中的段落
            for (int j = 0; j < footNote.getTextBody().getParagraphs().getCount(); j++) {
                Paragraph paragraph = footNote.getTextBody().getParagraphs().get(j);
                //遍历段落中的对象
               for(Object object : paragraph.getChildObjects()){
                   //读取文本
                   if (object instanceof TextRange) {
                       TextRange textRange = (TextRange) object;
                       str = str + textRange.getText();
                   }
               }
            }
        }
        //输出脚注文本
        System.out.println(str);
    }
} 脚注读取结果:

读取Word尾注
import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.Footnote;
import com.spire.doc.fields.TextRange;
import java.util.List;
public class ExtractFootnoteAndEndnote {
    public static void main(String[] args) {
        //创建Document实例
        Document doc = new Document();
        doc.loadFromFile("test1.docx");
       //获取所有尾注
        List endNotes = doc.getEndnotes();
        //实例化String类型变量
        String str = "";
        //遍历尾注
        for (Footnote endnote :endNotes) {
            //遍历尾注中的段落
            for (int j = 0; j < endnote.getTextBody().getParagraphs().getCount(); j++) {
                Paragraph paragraph = endnote.getTextBody().getParagraphs().get(j);
                //遍历段落中的对象
                for(Object object : paragraph.getChildObjects()){
                    //读取文本
                    if (object instanceof TextRange) {
                        TextRange textRange = (TextRange) object;
                        str = str + textRange.getText();
                    }
                }
            }
        }
        //输出尾注文本
        System.out.println(str);
    }
} 尾注读取结果:

 



 
					



