DOCX
文档属性
设置核心、扩展(app)和自定义文档属性
核心属性
核心元数据写入 docProps/core.xml,并在解析时读回。直接在文档选项上设置这些字段:
{
"title": "季度报告",
"subject": "财务",
"creator": "张三",
"keywords": "q4, 财务",
"description": "季度财务报告",
"revision": 2,
"sections": []
}
import { generateDocument } from "@office-open/docx";
const buffer = await generateDocument({
title: "季度报告",
subject: "财务",
creator: "张三",
keywords: "q4, 财务",
description: "季度财务报告",
revision: 2,
sections: [
/* … */
],
});
| 属性 | 类型 | 说明 |
|---|---|---|
title | string | 文档标题 |
subject | string | 主题 |
creator | string | 作者 |
keywords | string | 关键词 |
description | string | 描述 |
lastModifiedBy | string | 最后修改者 |
revision | number | 修订号 |
lastPrinted | string | 最后打印日期(W3CDTF) |
created | string | 创建日期(W3CDTF) |
modified | string | 最后修改日期(W3CDTF) |
扩展属性
appProperties 写入 docProps/app.xml。常用可设置字段为 template、manager、company 和 application;其余(pages、words、characters 等)是通常由 Office 计算的文档统计信息:
{
"appProperties": { "company": "Globex", "manager": "张三" },
"sections": []
}
import { generateDocument } from "@office-open/docx";
const buffer = await generateDocument({
appProperties: {
company: "Globex",
manager: "张三",
template: "report.dotx",
application: "office-open",
},
sections: [
/* … */
],
});
| 属性 | 类型 | 说明 |
|---|---|---|
template | string | 模板名称 |
manager | string | 经理名称 |
company | string | 公司名称 |
application | string | 应用程序名称 |
appVersion | string | 应用程序版本 |
pages | number | 页数 |
words | number | 字数 |
characters | number | 字符数 |
lines | number | 行数 |
paragraphs | number | 段落数 |
totalTime | number | 总编辑时间(分钟) |
hyperlinkBase | string | 超链接基础 URL |
docSecurity | number | 文档安全级别 |
自定义属性
customProperties 写入 docProps/custom.xml。每个值都是字符串:
{
"customProperties": [
{ "name": "ProjectId", "value": "PRJ-42" },
{ "name": "Department", "value": "Finance" }
],
"sections": []
}
import { generateDocument } from "@office-open/docx";
const buffer = await generateDocument({
customProperties: [
{ name: "ProjectId", value: "PRJ-42" },
{ name: "Department", value: "Finance" },
],
sections: [
/* … */
],
});
| 属性 | 类型 | 说明 |
|---|---|---|
name | string | 属性名称 |
value | string | 属性值 |