DOCXKIT_HEADER_FOOTER_INVALID_CONTENT: 页眉页脚内容无效
页眉或页脚插件返回了 Paragraph、Table 以外的元素。
修复步骤
- 页眉页脚内容返回 Paragraph 或 Table 实例。
- 将行内元素包装在 Paragraph 内。
问题示例
ts
import { TextRun } from 'docx'
// Invalid output from a plugin used in a header/footer:
const render = () => new TextRun('Header')修复示例
ts
import { Paragraph, TextRun } from 'docx'
// Valid output from a plugin used in a header/footer:
const render = () => new Paragraph({ children: [new TextRun('Header')] })常见原因
- 插件直接返回 TextRun 或其他不支持的子元素。
诊断字段
code:HEADER_FOOTER_INVALID_CONTENTdiagnosticCode:DOCXKIT_HEADER_FOOTER_INVALID_CONTENTname:DocxKitErrordocs: https://docx-kit.ntnyq.dev/errors/docxkit_header_footer_invalid_content/
消息示例
text
Header and footer plugins must render paragraphs or tables