jerry adc15f03a3 feat:导入大量文档和数据,完成一个可用的初版 2 hónapja
..
README.MD adc15f03a3 feat:导入大量文档和数据,完成一个可用的初版 2 hónapja
docxImage.ts adc15f03a3 feat:导入大量文档和数据,完成一个可用的初版 2 hónapja
docxList.ts adc15f03a3 feat:导入大量文档和数据,完成一个可用的初版 2 hónapja
docxMath.ts adc15f03a3 feat:导入大量文档和数据,完成一个可用的初版 2 hónapja
docxTable.ts adc15f03a3 feat:导入大量文档和数据,完成一个可用的初版 2 hónapja
docxText.ts adc15f03a3 feat:导入大量文档和数据,完成一个可用的初版 2 hónapja
docxTitle.ts adc15f03a3 feat:导入大量文档和数据,完成一个可用的初版 2 hónapja
globalConfig.ts adc15f03a3 feat:导入大量文档和数据,完成一个可用的初版 2 hónapja
handleElement.ts adc15f03a3 feat:导入大量文档和数据,完成一个可用的初版 2 hónapja
handleNodes.ts adc15f03a3 feat:导入大量文档和数据,完成一个可用的初版 2 hónapja
index.ts adc15f03a3 feat:导入大量文档和数据,完成一个可用的初版 2 hónapja
types.ts adc15f03a3 feat:导入大量文档和数据,完成一个可用的初版 2 hónapja

README.MD

About docx

用法

组件结构

Document
├── sections
│   ├── headers
│   ├── footers
│   ├── properties
│   ├── children(Paragraph | Table | TableOfContents | Textbox)
├── title
├── subject
├── creator
├── keywords
├── description
├── lastModifiedBy
├── revision
├── externalStyles
├── styles
├── numbering
├── comments
├── footnotes
├── background
├── features
├── compatabilityModeVersion
├── compatibility
├── customProperties
├── evenAndOddHeaderAndFooters
├── defaultTabStop
├── fonts
└── hyphenation

Document

组件结构

Document
├── sections
│   ├── headers
│   ├── footers
│   ├── properties
│   ├── children(Paragraph | Table | TableOfContents | Textbox)
├── title
├── subject
├── creator
├── keywords
├── description
├── lastModifiedBy
├── revision
├── externalStyles
├── styles
├── numbering
├── comments
├── footnotes
├── background
├── features
├── compatabilityModeVersion
├── compatibility
├── customProperties
├── evenAndOddHeaderAndFooters
├── defaultTabStop
├── fonts
└── hyphenation

选项表:

特殊字段说明

externalStyles

导入外部样式内容导入,内容格式为xml。

样式导入后,可在段落中设置指定样式。

代码示例:

// This example shows 3 styles using XML styles

import * as fs from "fs";
import { Document, HeadingLevel, Packer, Paragraph } from "docx";

const styles = fs.readFileSync("./demo/assets/custom-styles.xml", "utf-8");
const doc = new Document({
    title: "Title",
    externalStyles: styles,
    sections: [
        {
            children: [
                new Paragraph({
                    text: "Cool Heading Text",
                    heading: HeadingLevel.HEADING_1,
                }),
                new Paragraph({
                    text: 'This is a custom named style from the template "MyFancyStyle"',
                    style: "MyFancyStyle",
                }),
                new Paragraph("Some normal text"),
                new Paragraph({
                    text: "MyFancyStyle again",
                    style: "MyFancyStyle",
                }),
            ],
        },
    ],
});

Packer.toBuffer(doc).then((buffer) => {
    fs.writeFileSync("My Document.docx", buffer);
});

样式文件示例:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:styles xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
  xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
  xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" mc:Ignorable="w14 w15">
  <w:docDefaults>
    <w:rPrDefault>
      <w:rPr>
        <w:rFonts w:asciiTheme="minorHAnsi" w:eastAsiaTheme="minorHAnsi" w:hAnsiTheme="minorHAnsi"
          w:cstheme="minorBidi" />
        <w:sz w:val="22" />
        <w:szCs w:val="22" />
        <w:lang w:val="en-GB" w:eastAsia="en-US" w:bidi="ar-SA" />
      </w:rPr>
    </w:rPrDefault>
    <w:pPrDefault>
      <w:pPr>
        <w:spacing w:after="160" w:line="259" w:lineRule="auto" />
      </w:pPr>
    </w:pPrDefault>
  </w:docDefaults>
  <w:latentStyles w:defLockedState="0" w:defUIPriority="99" w:defSemiHidden="0"
    w:defUnhideWhenUsed="0" w:defQFormat="0" w:count="371">
    <w:lsdException w:name="Normal" w:uiPriority="0" w:qFormat="1" />
    <w:lsdException w:name="heading 1" w:uiPriority="9" w:qFormat="1" />
    <w:lsdException w:name="heading 2" w:semiHidden="1" w:uiPriority="9" w:unhideWhenUsed="1"
      w:qFormat="1" />
    <w:lsdException w:name="heading 3" w:semiHidden="1" w:uiPriority="9" w:unhideWhenUsed="1"
      w:qFormat="1" />
    <w:lsdException w:name="heading 4" w:semiHidden="1" w:uiPriority="9" w:unhideWhenUsed="1"
      w:qFormat="1" />
    <w:lsdException w:name="heading 5" w:semiHidden="1" w:uiPriority="9" w:unhideWhenUsed="1"
      w:qFormat="1" />
    <w:lsdException w:name="heading 6" w:semiHidden="1" w:uiPriority="9" w:unhideWhenUsed="1"
      w:qFormat="1" />
    <w:lsdException w:name="heading 7" w:semiHidden="1" w:uiPriority="9" w:unhideWhenUsed="1"
      w:qFormat="1" />
    <w:lsdException w:name="heading 8" w:semiHidden="1" w:uiPriority="9" w:unhideWhenUsed="1"
      w:qFormat="1" />
    <w:lsdException w:name="heading 9" w:semiHidden="1" w:uiPriority="9" w:unhideWhenUsed="1"
      w:qFormat="1" />
    <w:lsdException w:name="index 1" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="index 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="index 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="index 4" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="index 5" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="index 6" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="index 7" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="index 8" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="index 9" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="toc 1" w:semiHidden="1" w:uiPriority="39" w:unhideWhenUsed="1" />
    <w:lsdException w:name="toc 2" w:semiHidden="1" w:uiPriority="39" w:unhideWhenUsed="1" />
    <w:lsdException w:name="toc 3" w:semiHidden="1" w:uiPriority="39" w:unhideWhenUsed="1" />
    <w:lsdException w:name="toc 4" w:semiHidden="1" w:uiPriority="39" w:unhideWhenUsed="1" />
    <w:lsdException w:name="toc 5" w:semiHidden="1" w:uiPriority="39" w:unhideWhenUsed="1" />
    <w:lsdException w:name="toc 6" w:semiHidden="1" w:uiPriority="39" w:unhideWhenUsed="1" />
    <w:lsdException w:name="toc 7" w:semiHidden="1" w:uiPriority="39" w:unhideWhenUsed="1" />
    <w:lsdException w:name="toc 8" w:semiHidden="1" w:uiPriority="39" w:unhideWhenUsed="1" />
    <w:lsdException w:name="toc 9" w:semiHidden="1" w:uiPriority="39" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Normal Indent" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="footnote text" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="annotation text" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="header" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="footer" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="index heading" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="caption" w:semiHidden="1" w:uiPriority="35" w:unhideWhenUsed="1"
      w:qFormat="1" />
    <w:lsdException w:name="table of figures" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="envelope address" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="envelope return" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="footnote reference" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="annotation reference" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="line number" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="page number" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="endnote reference" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="endnote text" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="table of authorities" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="macro" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="toa heading" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List Bullet" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List Number" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List 4" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List 5" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List Bullet 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List Bullet 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List Bullet 4" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List Bullet 5" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List Number 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List Number 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List Number 4" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List Number 5" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Title" w:uiPriority="10" w:qFormat="1" />
    <w:lsdException w:name="Closing" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Signature" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Default Paragraph Font" w:semiHidden="1" w:uiPriority="1"
      w:unhideWhenUsed="1" />
    <w:lsdException w:name="Body Text" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Body Text Indent" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List Continue" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List Continue 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List Continue 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List Continue 4" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="List Continue 5" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Message Header" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Subtitle" w:uiPriority="11" w:qFormat="1" />
    <w:lsdException w:name="Salutation" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Date" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Body Text First Indent" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Body Text First Indent 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Note Heading" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Body Text 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Body Text 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Body Text Indent 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Body Text Indent 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Block Text" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Hyperlink" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="FollowedHyperlink" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Strong" w:uiPriority="22" w:qFormat="1" />
    <w:lsdException w:name="Emphasis" w:uiPriority="20" w:qFormat="1" />
    <w:lsdException w:name="Document Map" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Plain Text" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="E-mail Signature" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="HTML Top of Form" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="HTML Bottom of Form" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Normal (Web)" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="HTML Acronym" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="HTML Address" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="HTML Cite" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="HTML Code" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="HTML Definition" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="HTML Keyboard" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="HTML Preformatted" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="HTML Sample" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="HTML Typewriter" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="HTML Variable" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Normal Table" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="annotation subject" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="No List" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Outline List 1" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Outline List 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Outline List 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Simple 1" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Simple 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Simple 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Classic 1" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Classic 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Classic 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Classic 4" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Colorful 1" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Colorful 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Colorful 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Columns 1" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Columns 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Columns 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Columns 4" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Columns 5" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Grid 1" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Grid 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Grid 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Grid 4" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Grid 5" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Grid 6" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Grid 7" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Grid 8" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table List 1" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table List 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table List 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table List 4" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table List 5" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table List 6" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table List 7" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table List 8" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table 3D effects 1" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table 3D effects 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table 3D effects 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Contemporary" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Elegant" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Professional" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Subtle 1" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Subtle 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Web 1" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Web 2" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Web 3" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Balloon Text" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Table Grid" w:uiPriority="39" />
    <w:lsdException w:name="Table Theme" w:semiHidden="1" w:unhideWhenUsed="1" />
    <w:lsdException w:name="Placeholder Text" w:semiHidden="1" />
    <w:lsdException w:name="No Spacing" w:uiPriority="1" w:qFormat="1" />
    <w:lsdException w:name="Light Shading" w:uiPriority="60" />
    <w:lsdException w:name="Light List" w:uiPriority="61" />
    <w:lsdException w:name="Light Grid" w:uiPriority="62" />
    <w:lsdException w:name="Medium Shading 1" w:uiPriority="63" />
    <w:lsdException w:name="Medium Shading 2" w:uiPriority="64" />
    <w:lsdException w:name="Medium List 1" w:uiPriority="65" />
    <w:lsdException w:name="Medium List 2" w:uiPriority="66" />
    <w:lsdException w:name="Medium Grid 1" w:uiPriority="67" />
    <w:lsdException w:name="Medium Grid 2" w:uiPriority="68" />
    <w:lsdException w:name="Medium Grid 3" w:uiPriority="69" />
    <w:lsdException w:name="Dark List" w:uiPriority="70" />
    <w:lsdException w:name="Colorful Shading" w:uiPriority="71" />
    <w:lsdException w:name="Colorful List" w:uiPriority="72" />
    <w:lsdException w:name="Colorful Grid" w:uiPriority="73" />
    <w:lsdException w:name="Light Shading Accent 1" w:uiPriority="60" />
    <w:lsdException w:name="Light List Accent 1" w:uiPriority="61" />
    <w:lsdException w:name="Light Grid Accent 1" w:uiPriority="62" />
    <w:lsdException w:name="Medium Shading 1 Accent 1" w:uiPriority="63" />
    <w:lsdException w:name="Medium Shading 2 Accent 1" w:uiPriority="64" />
    <w:lsdException w:name="Medium List 1 Accent 1" w:uiPriority="65" />
    <w:lsdException w:name="Revision" w:semiHidden="1" />
    <w:lsdException w:name="List Paragraph" w:uiPriority="34" w:qFormat="1" />
    <w:lsdException w:name="Quote" w:uiPriority="29" w:qFormat="1" />
    <w:lsdException w:name="Intense Quote" w:uiPriority="30" w:qFormat="1" />
    <w:lsdException w:name="Medium List 2 Accent 1" w:uiPriority="66" />
    <w:lsdException w:name="Medium Grid 1 Accent 1" w:uiPriority="67" />
    <w:lsdException w:name="Medium Grid 2 Accent 1" w:uiPriority="68" />
    <w:lsdException w:name="Medium Grid 3 Accent 1" w:uiPriority="69" />
    <w:lsdException w:name="Dark List Accent 1" w:uiPriority="70" />
    <w:lsdException w:name="Colorful Shading Accent 1" w:uiPriority="71" />
    <w:lsdException w:name="Colorful List Accent 1" w:uiPriority="72" />
    <w:lsdException w:name="Colorful Grid Accent 1" w:uiPriority="73" />
    <w:lsdException w:name="Light Shading Accent 2" w:uiPriority="60" />
    <w:lsdException w:name="Light List Accent 2" w:uiPriority="61" />
    <w:lsdException w:name="Light Grid Accent 2" w:uiPriority="62" />
    <w:lsdException w:name="Medium Shading 1 Accent 2" w:uiPriority="63" />
    <w:lsdException w:name="Medium Shading 2 Accent 2" w:uiPriority="64" />
    <w:lsdException w:name="Medium List 1 Accent 2" w:uiPriority="65" />
    <w:lsdException w:name="Medium List 2 Accent 2" w:uiPriority="66" />
    <w:lsdException w:name="Medium Grid 1 Accent 2" w:uiPriority="67" />
    <w:lsdException w:name="Medium Grid 2 Accent 2" w:uiPriority="68" />
    <w:lsdException w:name="Medium Grid 3 Accent 2" w:uiPriority="69" />
    <w:lsdException w:name="Dark List Accent 2" w:uiPriority="70" />
    <w:lsdException w:name="Colorful Shading Accent 2" w:uiPriority="71" />
    <w:lsdException w:name="Colorful List Accent 2" w:uiPriority="72" />
    <w:lsdException w:name="Colorful Grid Accent 2" w:uiPriority="73" />
    <w:lsdException w:name="Light Shading Accent 3" w:uiPriority="60" />
    <w:lsdException w:name="Light List Accent 3" w:uiPriority="61" />
    <w:lsdException w:name="Light Grid Accent 3" w:uiPriority="62" />
    <w:lsdException w:name="Medium Shading 1 Accent 3" w:uiPriority="63" />
    <w:lsdException w:name="Medium Shading 2 Accent 3" w:uiPriority="64" />
    <w:lsdException w:name="Medium List 1 Accent 3" w:uiPriority="65" />
    <w:lsdException w:name="Medium List 2 Accent 3" w:uiPriority="66" />
    <w:lsdException w:name="Medium Grid 1 Accent 3" w:uiPriority="67" />
    <w:lsdException w:name="Medium Grid 2 Accent 3" w:uiPriority="68" />
    <w:lsdException w:name="Medium Grid 3 Accent 3" w:uiPriority="69" />
    <w:lsdException w:name="Dark List Accent 3" w:uiPriority="70" />
    <w:lsdException w:name="Colorful Shading Accent 3" w:uiPriority="71" />
    <w:lsdException w:name="Colorful List Accent 3" w:uiPriority="72" />
    <w:lsdException w:name="Colorful Grid Accent 3" w:uiPriority="73" />
    <w:lsdException w:name="Light Shading Accent 4" w:uiPriority="60" />
    <w:lsdException w:name="Light List Accent 4" w:uiPriority="61" />
    <w:lsdException w:name="Light Grid Accent 4" w:uiPriority="62" />
    <w:lsdException w:name="Medium Shading 1 Accent 4" w:uiPriority="63" />
    <w:lsdException w:name="Medium Shading 2 Accent 4" w:uiPriority="64" />
    <w:lsdException w:name="Medium List 1 Accent 4" w:uiPriority="65" />
    <w:lsdException w:name="Medium List 2 Accent 4" w:uiPriority="66" />
    <w:lsdException w:name="Medium Grid 1 Accent 4" w:uiPriority="67" />
    <w:lsdException w:name="Medium Grid 2 Accent 4" w:uiPriority="68" />
    <w:lsdException w:name="Medium Grid 3 Accent 4" w:uiPriority="69" />
    <w:lsdException w:name="Dark List Accent 4" w:uiPriority="70" />
    <w:lsdException w:name="Colorful Shading Accent 4" w:uiPriority="71" />
    <w:lsdException w:name="Colorful List Accent 4" w:uiPriority="72" />
    <w:lsdException w:name="Colorful Grid Accent 4" w:uiPriority="73" />
    <w:lsdException w:name="Light Shading Accent 5" w:uiPriority="60" />
    <w:lsdException w:name="Light List Accent 5" w:uiPriority="61" />
    <w:lsdException w:name="Light Grid Accent 5" w:uiPriority="62" />
    <w:lsdException w:name="Medium Shading 1 Accent 5" w:uiPriority="63" />
    <w:lsdException w:name="Medium Shading 2 Accent 5" w:uiPriority="64" />
    <w:lsdException w:name="Medium List 1 Accent 5" w:uiPriority="65" />
    <w:lsdException w:name="Medium List 2 Accent 5" w:uiPriority="66" />
    <w:lsdException w:name="Medium Grid 1 Accent 5" w:uiPriority="67" />
    <w:lsdException w:name="Medium Grid 2 Accent 5" w:uiPriority="68" />
    <w:lsdException w:name="Medium Grid 3 Accent 5" w:uiPriority="69" />
    <w:lsdException w:name="Dark List Accent 5" w:uiPriority="70" />
    <w:lsdException w:name="Colorful Shading Accent 5" w:uiPriority="71" />
    <w:lsdException w:name="Colorful List Accent 5" w:uiPriority="72" />
    <w:lsdException w:name="Colorful Grid Accent 5" w:uiPriority="73" />
    <w:lsdException w:name="Light Shading Accent 6" w:uiPriority="60" />
    <w:lsdException w:name="Light List Accent 6" w:uiPriority="61" />
    <w:lsdException w:name="Light Grid Accent 6" w:uiPriority="62" />
    <w:lsdException w:name="Medium Shading 1 Accent 6" w:uiPriority="63" />
    <w:lsdException w:name="Medium Shading 2 Accent 6" w:uiPriority="64" />
    <w:lsdException w:name="Medium List 1 Accent 6" w:uiPriority="65" />
    <w:lsdException w:name="Medium List 2 Accent 6" w:uiPriority="66" />
    <w:lsdException w:name="Medium Grid 1 Accent 6" w:uiPriority="67" />
    <w:lsdException w:name="Medium Grid 2 Accent 6" w:uiPriority="68" />
    <w:lsdException w:name="Medium Grid 3 Accent 6" w:uiPriority="69" />
    <w:lsdException w:name="Dark List Accent 6" w:uiPriority="70" />
    <w:lsdException w:name="Colorful Shading Accent 6" w:uiPriority="71" />
    <w:lsdException w:name="Colorful List Accent 6" w:uiPriority="72" />
    <w:lsdException w:name="Colorful Grid Accent 6" w:uiPriority="73" />
    <w:lsdException w:name="Subtle Emphasis" w:uiPriority="19" w:qFormat="1" />
    <w:lsdException w:name="Intense Emphasis" w:uiPriority="21" w:qFormat="1" />
    <w:lsdException w:name="Subtle Reference" w:uiPriority="31" w:qFormat="1" />
    <w:lsdException w:name="Intense Reference" w:uiPriority="32" w:qFormat="1" />
    <w:lsdException w:name="Book Title" w:uiPriority="33" w:qFormat="1" />
    <w:lsdException w:name="Bibliography" w:semiHidden="1" w:uiPriority="37" w:unhideWhenUsed="1" />
    <w:lsdException w:name="TOC Heading" w:semiHidden="1" w:uiPriority="39" w:unhideWhenUsed="1"
      w:qFormat="1" />
    <w:lsdException w:name="Plain Table 1" w:uiPriority="41" />
    <w:lsdException w:name="Plain Table 2" w:uiPriority="42" />
    <w:lsdException w:name="Plain Table 3" w:uiPriority="43" />
    <w:lsdException w:name="Plain Table 4" w:uiPriority="44" />
    <w:lsdException w:name="Plain Table 5" w:uiPriority="45" />
    <w:lsdException w:name="Grid Table Light" w:uiPriority="40" />
    <w:lsdException w:name="Grid Table 1 Light" w:uiPriority="46" />
    <w:lsdException w:name="Grid Table 2" w:uiPriority="47" />
    <w:lsdException w:name="Grid Table 3" w:uiPriority="48" />
    <w:lsdException w:name="Grid Table 4" w:uiPriority="49" />
    <w:lsdException w:name="Grid Table 5 Dark" w:uiPriority="50" />
    <w:lsdException w:name="Grid Table 6 Colorful" w:uiPriority="51" />
    <w:lsdException w:name="Grid Table 7 Colorful" w:uiPriority="52" />
    <w:lsdException w:name="Grid Table 1 Light Accent 1" w:uiPriority="46" />
    <w:lsdException w:name="Grid Table 2 Accent 1" w:uiPriority="47" />
    <w:lsdException w:name="Grid Table 3 Accent 1" w:uiPriority="48" />
    <w:lsdException w:name="Grid Table 4 Accent 1" w:uiPriority="49" />
    <w:lsdException w:name="Grid Table 5 Dark Accent 1" w:uiPriority="50" />
    <w:lsdException w:name="Grid Table 6 Colorful Accent 1" w:uiPriority="51" />
    <w:lsdException w:name="Grid Table 7 Colorful Accent 1" w:uiPriority="52" />
    <w:lsdException w:name="Grid Table 1 Light Accent 2" w:uiPriority="46" />
    <w:lsdException w:name="Grid Table 2 Accent 2" w:uiPriority="47" />
    <w:lsdException w:name="Grid Table 3 Accent 2" w:uiPriority="48" />
    <w:lsdException w:name="Grid Table 4 Accent 2" w:uiPriority="49" />
    <w:lsdException w:name="Grid Table 5 Dark Accent 2" w:uiPriority="50" />
    <w:lsdException w:name="Grid Table 6 Colorful Accent 2" w:uiPriority="51" />
    <w:lsdException w:name="Grid Table 7 Colorful Accent 2" w:uiPriority="52" />
    <w:lsdException w:name="Grid Table 1 Light Accent 3" w:uiPriority="46" />
    <w:lsdException w:name="Grid Table 2 Accent 3" w:uiPriority="47" />
    <w:lsdException w:name="Grid Table 3 Accent 3" w:uiPriority="48" />
    <w:lsdException w:name="Grid Table 4 Accent 3" w:uiPriority="49" />
    <w:lsdException w:name="Grid Table 5 Dark Accent 3" w:uiPriority="50" />
    <w:lsdException w:name="Grid Table 6 Colorful Accent 3" w:uiPriority="51" />
    <w:lsdException w:name="Grid Table 7 Colorful Accent 3" w:uiPriority="52" />
    <w:lsdException w:name="Grid Table 1 Light Accent 4" w:uiPriority="46" />
    <w:lsdException w:name="Grid Table 2 Accent 4" w:uiPriority="47" />
    <w:lsdException w:name="Grid Table 3 Accent 4" w:uiPriority="48" />
    <w:lsdException w:name="Grid Table 4 Accent 4" w:uiPriority="49" />
    <w:lsdException w:name="Grid Table 5 Dark Accent 4" w:uiPriority="50" />
    <w:lsdException w:name="Grid Table 6 Colorful Accent 4" w:uiPriority="51" />
    <w:lsdException w:name="Grid Table 7 Colorful Accent 4" w:uiPriority="52" />
    <w:lsdException w:name="Grid Table 1 Light Accent 5" w:uiPriority="46" />
    <w:lsdException w:name="Grid Table 2 Accent 5" w:uiPriority="47" />
    <w:lsdException w:name="Grid Table 3 Accent 5" w:uiPriority="48" />
    <w:lsdException w:name="Grid Table 4 Accent 5" w:uiPriority="49" />
    <w:lsdException w:name="Grid Table 5 Dark Accent 5" w:uiPriority="50" />
    <w:lsdException w:name="Grid Table 6 Colorful Accent 5" w:uiPriority="51" />
    <w:lsdException w:name="Grid Table 7 Colorful Accent 5" w:uiPriority="52" />
    <w:lsdException w:name="Grid Table 1 Light Accent 6" w:uiPriority="46" />
    <w:lsdException w:name="Grid Table 2 Accent 6" w:uiPriority="47" />
    <w:lsdException w:name="Grid Table 3 Accent 6" w:uiPriority="48" />
    <w:lsdException w:name="Grid Table 4 Accent 6" w:uiPriority="49" />
    <w:lsdException w:name="Grid Table 5 Dark Accent 6" w:uiPriority="50" />
    <w:lsdException w:name="Grid Table 6 Colorful Accent 6" w:uiPriority="51" />
    <w:lsdException w:name="Grid Table 7 Colorful Accent 6" w:uiPriority="52" />
    <w:lsdException w:name="List Table 1 Light" w:uiPriority="46" />
    <w:lsdException w:name="List Table 2" w:uiPriority="47" />
    <w:lsdException w:name="List Table 3" w:uiPriority="48" />
    <w:lsdException w:name="List Table 4" w:uiPriority="49" />
    <w:lsdException w:name="List Table 5 Dark" w:uiPriority="50" />
    <w:lsdException w:name="List Table 6 Colorful" w:uiPriority="51" />
    <w:lsdException w:name="List Table 7 Colorful" w:uiPriority="52" />
    <w:lsdException w:name="List Table 1 Light Accent 1" w:uiPriority="46" />
    <w:lsdException w:name="List Table 2 Accent 1" w:uiPriority="47" />
    <w:lsdException w:name="List Table 3 Accent 1" w:uiPriority="48" />
    <w:lsdException w:name="List Table 4 Accent 1" w:uiPriority="49" />
    <w:lsdException w:name="List Table 5 Dark Accent 1" w:uiPriority="50" />
    <w:lsdException w:name="List Table 6 Colorful Accent 1" w:uiPriority="51" />
    <w:lsdException w:name="List Table 7 Colorful Accent 1" w:uiPriority="52" />
    <w:lsdException w:name="List Table 1 Light Accent 2" w:uiPriority="46" />
    <w:lsdException w:name="List Table 2 Accent 2" w:uiPriority="47" />
    <w:lsdException w:name="List Table 3 Accent 2" w:uiPriority="48" />
    <w:lsdException w:name="List Table 4 Accent 2" w:uiPriority="49" />
    <w:lsdException w:name="List Table 5 Dark Accent 2" w:uiPriority="50" />
    <w:lsdException w:name="List Table 6 Colorful Accent 2" w:uiPriority="51" />
    <w:lsdException w:name="List Table 7 Colorful Accent 2" w:uiPriority="52" />
    <w:lsdException w:name="List Table 1 Light Accent 3" w:uiPriority="46" />
    <w:lsdException w:name="List Table 2 Accent 3" w:uiPriority="47" />
    <w:lsdException w:name="List Table 3 Accent 3" w:uiPriority="48" />
    <w:lsdException w:name="List Table 4 Accent 3" w:uiPriority="49" />
    <w:lsdException w:name="List Table 5 Dark Accent 3" w:uiPriority="50" />
    <w:lsdException w:name="List Table 6 Colorful Accent 3" w:uiPriority="51" />
    <w:lsdException w:name="List Table 7 Colorful Accent 3" w:uiPriority="52" />
    <w:lsdException w:name="List Table 1 Light Accent 4" w:uiPriority="46" />
    <w:lsdException w:name="List Table 2 Accent 4" w:uiPriority="47" />
    <w:lsdException w:name="List Table 3 Accent 4" w:uiPriority="48" />
    <w:lsdException w:name="List Table 4 Accent 4" w:uiPriority="49" />
    <w:lsdException w:name="List Table 5 Dark Accent 4" w:uiPriority="50" />
    <w:lsdException w:name="List Table 6 Colorful Accent 4" w:uiPriority="51" />
    <w:lsdException w:name="List Table 7 Colorful Accent 4" w:uiPriority="52" />
    <w:lsdException w:name="List Table 1 Light Accent 5" w:uiPriority="46" />
    <w:lsdException w:name="List Table 2 Accent 5" w:uiPriority="47" />
    <w:lsdException w:name="List Table 3 Accent 5" w:uiPriority="48" />
    <w:lsdException w:name="List Table 4 Accent 5" w:uiPriority="49" />
    <w:lsdException w:name="List Table 5 Dark Accent 5" w:uiPriority="50" />
    <w:lsdException w:name="List Table 6 Colorful Accent 5" w:uiPriority="51" />
    <w:lsdException w:name="List Table 7 Colorful Accent 5" w:uiPriority="52" />
    <w:lsdException w:name="List Table 1 Light Accent 6" w:uiPriority="46" />
    <w:lsdException w:name="List Table 2 Accent 6" w:uiPriority="47" />
    <w:lsdException w:name="List Table 3 Accent 6" w:uiPriority="48" />
    <w:lsdException w:name="List Table 4 Accent 6" w:uiPriority="49" />
    <w:lsdException w:name="List Table 5 Dark Accent 6" w:uiPriority="50" />
    <w:lsdException w:name="List Table 6 Colorful Accent 6" w:uiPriority="51" />
    <w:lsdException w:name="List Table 7 Colorful Accent 6" w:uiPriority="52" />
  </w:latentStyles>
  <w:style w:type="paragraph" w:default="1" w:styleId="Normal">
    <w:name w:val="Normal" />
    <w:qFormat />
    <w:rsid w:val="000D2D99" />
    <w:rPr>
      <w:rFonts w:ascii="MV Boli" w:hAnsi="MV Boli" />
      <w:color w:val="C45911" w:themeColor="accent2" w:themeShade="BF" />
    </w:rPr>
  </w:style>
  <w:style w:type="paragraph" w:styleId="Heading1">
    <w:name w:val="heading 1" />
    <w:basedOn w:val="Normal" />
    <w:next w:val="Normal" />
    <w:link w:val="Heading1Char" />
    <w:uiPriority w:val="9" />
    <w:qFormat />
    <w:rsid w:val="000D2D99" />
    <w:pPr>
      <w:keepNext />
      <w:keepLines />
      <w:spacing w:before="240" w:after="0" />
      <w:outlineLvl w:val="0" />
    </w:pPr>
    <w:rPr>
      <w:rFonts w:ascii="Impact" w:eastAsiaTheme="majorEastAsia" w:hAnsi="Impact"
        w:cstheme="majorBidi" />
      <w:color w:val="538135" w:themeColor="accent6" w:themeShade="BF" />
      <w:sz w:val="32" />
      <w:szCs w:val="32" />
    </w:rPr>
  </w:style>
  <w:style w:type="character" w:default="1" w:styleId="DefaultParagraphFont">
    <w:name w:val="Default Paragraph Font" />
    <w:uiPriority w:val="1" />
    <w:semiHidden />
    <w:unhideWhenUsed />
  </w:style>
  <w:style w:type="table" w:default="1" w:styleId="TableNormal">
    <w:name w:val="Normal Table" />
    <w:uiPriority w:val="99" />
    <w:semiHidden />
    <w:unhideWhenUsed />
    <w:tblPr>
      <w:tblInd w:w="0" w:type="dxa" />
      <w:tblCellMar>
        <w:top w:w="0" w:type="dxa" />
        <w:left w:w="108" w:type="dxa" />
        <w:bottom w:w="0" w:type="dxa" />
        <w:right w:w="108" w:type="dxa" />
      </w:tblCellMar>
    </w:tblPr>
  </w:style>
  <w:style w:type="table" w:customStyle="1" w:styleId="MyCustomTableStyle">
    <w:name w:val="My Custom TableStyle" />
    <w:uiPriority w:val="99" />
    <w:rsid w:val="00C36BA2" />
    <w:pPr>
      <w:spacing w:after="0" w:line="240" w:lineRule="auto" />
    </w:pPr>
    <w:rPr>
      <w:rFonts w:ascii="Comic Sans MS" w:hAnsi="Comic Sans MS" />
      <w:szCs w:val="20" />
      <w:lang w:val="en-US" />
    </w:rPr>
    <w:tblPr>
      <w:tblBorders>
        <w:top w:val="dashSmallGap" w:sz="6" w:space="0" w:color="FF0000" />
        <w:left w:val="dashSmallGap" w:sz="6" w:space="0" w:color="FF0000" />
        <w:bottom w:val="dashSmallGap" w:sz="6" w:space="0" w:color="FF0000" />
        <w:right w:val="dashSmallGap" w:sz="6" w:space="0" w:color="FF0000" />
        <w:insideH w:val="dashSmallGap" w:sz="6" w:space="0" w:color="FF0000" />
        <w:insideV w:val="dashSmallGap" w:sz="6" w:space="0" w:color="FF0000" />
      </w:tblBorders>
    </w:tblPr>
    <w:tcPr>
      <w:shd w:val="clear" w:color="auto" w:fill="auto" />
    </w:tcPr>
    <w:tblStylePr w:type="firstRow">
      <w:rPr>
        <w:b />
        <w:bCs />
        <w:color w:val="FFFFFF" w:themeColor="background1" />
      </w:rPr>
      <w:tblPr />
      <w:tcPr>
        <w:tcBorders>
          <w:tl2br w:val="none" w:sz="0" w:space="0" w:color="auto" />
          <w:tr2bl w:val="none" w:sz="0" w:space="0" w:color="auto" />
        </w:tcBorders>
        <w:shd w:val="clear" w:color="auto" w:fill="4472C4" w:themeFill="accent1" />
      </w:tcPr>
    </w:tblStylePr>
  </w:style>
  <w:style w:type="numbering" w:default="1" w:styleId="NoList">
    <w:name w:val="No List" />
    <w:uiPriority w:val="99" />
    <w:semiHidden />
    <w:unhideWhenUsed />
  </w:style>
  <w:style w:type="paragraph" w:customStyle="1" w:styleId="CustomStyle">
    <w:name w:val="Custom Style" />
    <w:basedOn w:val="Normal" />
    <w:link w:val="CustomStyleChar" />
    <w:rsid w:val="00B557A5" />
    <w:rPr>
      <w:sz w:val="72" />
    </w:rPr>
  </w:style>
  <w:style w:type="character" w:customStyle="1" w:styleId="CustomStyleChar">
    <w:name w:val="Custom Style Char" />
    <w:basedOn w:val="DefaultParagraphFont" />
    <w:link w:val="CustomStyle" />
    <w:rsid w:val="00B557A5" />
    <w:rPr>
      <w:rFonts w:ascii="MV Boli" w:hAnsi="MV Boli" />
      <w:color w:val="C45911" w:themeColor="accent2" w:themeShade="BF" />
      <w:sz w:val="72" />
    </w:rPr>
  </w:style>
  <w:style w:type="character" w:customStyle="1" w:styleId="Heading1Char">
    <w:name w:val="Heading 1 Char" />
    <w:basedOn w:val="DefaultParagraphFont" />
    <w:link w:val="Heading1" />
    <w:uiPriority w:val="9" />
    <w:rsid w:val="000D2D99" />
    <w:rPr>
      <w:rFonts w:ascii="Impact" w:eastAsiaTheme="majorEastAsia" w:hAnsi="Impact"
        w:cstheme="majorBidi" />
      <w:color w:val="538135" w:themeColor="accent6" w:themeShade="BF" />
      <w:sz w:val="32" />
      <w:szCs w:val="32" />
    </w:rPr>
  </w:style>
  <w:style w:type="paragraph" w:customStyle="1" w:styleId="MyFancyStyle">
    <w:name w:val="MyFancyStyle" />
    <w:basedOn w:val="Normal" />
    <w:link w:val="MyFancyStyleChar" />
    <w:qFormat />
    <w:rsid w:val="008802A5" />
    <w:rPr>
      <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" />
      <w:color w:val="FF0000" />
      <w:sz w:val="144" />
    </w:rPr>
  </w:style>
  <w:style w:type="character" w:customStyle="1" w:styleId="MyFancyStyleChar">
    <w:name w:val="MyFancyStyle Char" />
    <w:basedOn w:val="DefaultParagraphFont" />
    <w:link w:val="MyFancyStyle" />
    <w:rsid w:val="008802A5" />
    <w:rPr>
      <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" />
      <w:color w:val="FF0000" />
      <w:sz w:val="144" />
    </w:rPr>
  </w:style>
</w:styles>

features

本字段可以实现配置变更跟踪和目录更新

变更跟踪

启用 trackRevisions 功能后,可实现自动跟踪文档新的修订。

import { Document } from "docx";

const doc = new Document({
    features: {
        trackRevisions: true,
    },
});

目录更新

必须启用 updateFields 功能才能正确更新 TableOfContents。

const doc = new Document({
    features: {
        updateFields: true,
    },
    sections: [
        {
            children: [
                new TableOfContents("Summary", {
                    hyperlink: true,
                    headingStyleRange: "1-5",
                }),
                new Paragraph({
                    text: "Header #1",
                    heading: HeadingLevel.HEADING_1,
                    pageBreakBefore: true,
                }),
            ]
        }
    ]
});

compatabilityModeVersion

兼容模式是指当你用较新版本的 Word 打开一个旧版本(如 Word 97-2003 .doc)的文档,或者从老版本升级而未转换为最新格式时,Word 会进入 兼容模式(Compatibility Mode)。此模式会:

  • 禁用一些新特性(如新样式、新对象)
  • 模拟旧版本的渲染方式
  • 避免向后不兼容
属性 类型 说明
sections ISectionOptions[] 各章节相关内容
title string 文章标题,仅为文件的属性
subject string 文章主题,仅为文件的属性
creator string 文章作者,仅为文件的属性
keywords string 文章关键词,仅为文件的属性
description string 文章描述,仅为文件的属性
lastModifiedBy string 文章最后修订者
revision string 文章修订版本号
externalStyles string 文章修订版本号
styles IStylesOptions 配置文档样式,待研究
numbering INumberingOptions 有序/无序列表编号配置
comments ICommentsOptions 评论配置
footnotes Record 脚注配置
background IDocumentBackgroundOptions 文档背景配置
features { trackRevisions?: boolean; updateFields?: boolean; } 特征配置
compatabilityModeVersion number 兼容模式版本
compatibility ICompatibilityOptions 兼容性配置
Version 对应 Word 版本 说明
11 Word 2003 .doc 格式兼容模式
12 Word 2007 早期 .docx 格式
14 Word 2010 支持部分新样式
15 Word 2013 默认兼容版本之一
16 Word 2016/2019/365 最新兼容模式

compatibility

兼容性设置是可选设置,用于保留早期文字处理应用程序中创建的文档的视觉保真度。其中一些设置提供了特定行为的功能(详见下文);而其他设置则只是指示应用程序模仿现有文字处理应用程序的行为。

const doc = new docx.Document({
    compatibility: {
        version: 15,
        doNotExpandShiftReturn: true,
    },
});

兼容性选项表:

属性 类型 值 说明
version number 15, 16, 17 最小兼容版本
useSingleBorderforContiguousCells boolean true, false, undefined 相邻单元格仅绘制一条边框,模仿旧 Word 表格合并边框行为
wordPerfectJustification boolean true, false, undefined
noTabStopForHangingIndent boolean true, false, undefined
noLeading boolean true, false, undefined
spaceForUnderline boolean true, false, undefined
noColumnBalance boolean true, false, undefined
balanceSingleByteDoubleByteWidth boolean true, false, undefined
noExtraLineSpacing boolean true, false, undefined
doNotLeaveBackslashAlone boolean true, false, undefined 不要单独使用反斜杠
underlineTrailingSpaces boolean true, false, undefined 给尾随空格加下划线
doNotExpandShiftReturn boolean true, false, undefined 尾随空格换行
spacingInWholePoints boolean true, false, undefined
lineWrapLikeWord6 boolean true, false, undefined 模仿 Word 6 的自动换行规则
printBodyTextBeforeHeader boolean true, false, undefined
printColorsBlack boolean true, false, undefined
spaceWidth boolean true, false, undefined
showBreaksInFrames boolean true, false, undefined
subFontBySize boolean true, false, undefined
suppressBottomSpacing boolean true, false, undefined
suppressTopSpacing boolean true, false, undefined
suppressSpacingAtTopOfPage boolean true, false, undefined
suppressTopSpacingWP boolean true, false, undefined
suppressSpBfAfterPgBrk boolean true, false, undefined
swapBordersFacingPages boolean true, false, undefined
convertMailMergeEsc boolean true, false, undefined
truncateFontHeightsLikeWP6 boolean true, false, undefined
macWordSmallCaps boolean true, false, undefined
usePrinterMetrics boolean true, false, undefined
doNotSuppressParagraphBorders boolean true, false, undefined
wrapTrailSpaces boolean true, false, undefined
footnoteLayoutLikeWW8 boolean true, false, undefined
shapeLayoutLikeWW8 boolean true, false, undefined
alignTablesRowByRow boolean true, false, undefined 表格逐行排列,不一次性渲染整表,以保持旧版 Word 排版一致
forgetLastTabAlignment boolean true, false, undefined
adjustLineHeightInTable boolean true, false, undefined
autoSpaceLikeWord95 boolean true, false, undefined
noSpaceRaiseLower boolean true, false, undefined
doNotUseHTMLParagraphAutoSpacing boolean true, false, undefined
layoutRawTableWidth boolean true, false, undefined 控制旧版 Word 处理表格宽度的方式
layoutTableRowsApart boolean true, false, undefined 控制旧版 Word 处理表格行间距的方式
useWord97LineBreakRules boolean true, false, undefined 模仿Word 97 的自动换行规则
doNotBreakWrappedTables boolean true, false, undefined 防止表格在文本换行点拆分
doNotSnapToGridInCell boolean true, false, undefined
selectFieldWithFirstOrLastCharacter boolean true, false, undefined
applyBreakingRules boolean true, false, undefined
doNotWrapTextWithPunctuation boolean true, false, undefined
doNotUseEastAsianBreakRules boolean true, false, undefined
useWord2002TableStyleRules boolean true, false, undefined
growAutofit boolean true, false, undefined
useFELayout boolean true, false, undefined
useNormalStyleForList boolean true, false, undefined
doNotUseIndentAsNumberingTabStop boolean true, false, undefined
useAlternateEastAsianLineBreakRules boolean true, false, undefined
allowSpaceOfSameStyleInTable boolean true, false, undefined
doNotSuppressIndentation boolean true, false, undefined
doNotAutofitConstrainedTables boolean true, false, undefined 关闭受限表格的自动调整
autofitToFirstFixedWidthCell boolean true, false, undefined 仅根据首列的固定宽度进行自适应
underlineTabInNumberingList boolean true, false, undefined
displayHangulFixedWidth boolean true, false, undefined
splitPgBreakAndParaMark boolean true, false, undefined
doNotVerticallyAlignCellWithSp boolean true, false, undefined
doNotBreakConstrainedForcedTable boolean true, false, undefined
ignoreVerticalAlignmentInTextboxes boolean true, false, undefined
useAnsiKerningPairs boolean true, false, undefined
cachedColumnBalance boolean true, false, undefined

Paragraph

Paragraph
├── TextRun
├── ImageRun
├── SymbolRun
├── Bookmark
├── PageBreak
├── ColumnBreak
├── SequentialIdentifier
├── FootnoteReferenceRun
├── InternalHyperlink
├── ExternalHyperlink
├── InsertedTextRun/DeletedTextRun
├── Math
├── SimpleField/SimpleMailMergeField
├── CommentRangeStart/CommentRangeEnd
├── CommentReference/Comments/Comment
└── CheckBox

Table

TableOfContents

Textbox