DOCX

引用

目录、脚注、尾注和参考文献

目录

插入一个可由 Word 应用程序更新的目录域:

import { Document, Paragraph, TableOfContents, TextRun } from "@office-open/docx";

const doc = new Document({
    sections: [
        {
            children: [
                new Paragraph({
                    heading: "Heading1",
                    children: [new TextRun("Table of Contents")],
                }),
                new TableOfContents("Table of Contents", {
                    hyperlink: true,
                    headingStyleRange: "1-3",
                }),
            ],
        },
    ],
});

脚注

在页面底部添加脚注:

import { Document, Paragraph, TextRun, FootnoteReferenceRun } from "@office-open/docx";

const doc = new Document({
    footnotes: {
        1: { children: [new Paragraph("This is the first footnote.")] },
        2: { children: [new Paragraph("This is the second footnote.")] },
    },
    sections: [
        {
            children: [
                new Paragraph({
                    children: [
                        new TextRun("A statement with a footnote"),
                        new FootnoteReferenceRun(1),
                        new TextRun(" and another"),
                        new FootnoteReferenceRun(2),
                        new TextRun("."),
                    ],
                }),
            ],
        },
    ],
});

尾注

尾注出现在文档或节的末尾:

import { EndnoteReferenceRun } from "@office-open/docx";

const doc = new Document({
    endnotes: {
        1: { children: [new Paragraph("This is an endnote.")] },
    },
    sections: [
        {
            children: [
                new Paragraph({
                    children: [new TextRun("Text with an endnote"), new EndnoteReferenceRun(1)],
                }),
            ],
        },
    ],
});

参考文献

添加参考文献节用于引用:

import { Bibliography } from "@office-open/docx";

// 参考文献条目通常通过 XML 源定义
// 并通过文档中的引用域进行引用
Copyright © 2026