simple-skills 1.3.8 → 1.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/README.md +1 -2
  2. package/package.json +1 -1
  3. package/skills/engineering/README.md +1 -2
  4. package/skills/engineering/officedocs/SKILL.md +306 -0
  5. package/skills/engineering/docx/SKILL.md +0 -617
  6. package/skills/engineering/docx/scripts/office/__pycache__/soffice.cpython-314.pyc +0 -0
  7. package/skills/engineering/docx/scripts/office/helpers/__pycache__/__init__.cpython-314.pyc +0 -0
  8. package/skills/engineering/docx/scripts/office/helpers/__pycache__/merge_runs.cpython-314.pyc +0 -0
  9. package/skills/engineering/docx/scripts/office/helpers/__pycache__/simplify_redlines.cpython-314.pyc +0 -0
  10. package/skills/engineering/pptx/SKILL.md +0 -221
  11. package/skills/engineering/pptx/scripts/__init__.py +0 -0
  12. package/skills/engineering/pptx/scripts/office/helpers/__init__.py +0 -0
  13. package/skills/engineering/pptx/scripts/office/helpers/merge_runs.py +0 -199
  14. package/skills/engineering/pptx/scripts/office/helpers/simplify_redlines.py +0 -197
  15. package/skills/engineering/pptx/scripts/office/pack.py +0 -159
  16. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +0 -1499
  17. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +0 -146
  18. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +0 -1085
  19. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +0 -11
  20. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +0 -3081
  21. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +0 -23
  22. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +0 -185
  23. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +0 -287
  24. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +0 -1676
  25. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +0 -28
  26. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +0 -144
  27. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +0 -174
  28. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +0 -25
  29. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +0 -18
  30. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +0 -59
  31. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +0 -56
  32. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +0 -195
  33. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +0 -582
  34. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +0 -25
  35. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +0 -4439
  36. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +0 -570
  37. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +0 -509
  38. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +0 -12
  39. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +0 -108
  40. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +0 -96
  41. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +0 -3646
  42. package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +0 -116
  43. package/skills/engineering/pptx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +0 -42
  44. package/skills/engineering/pptx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +0 -50
  45. package/skills/engineering/pptx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +0 -49
  46. package/skills/engineering/pptx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +0 -33
  47. package/skills/engineering/pptx/scripts/office/schemas/mce/mc.xsd +0 -75
  48. package/skills/engineering/pptx/scripts/office/schemas/microsoft/wml-2010.xsd +0 -560
  49. package/skills/engineering/pptx/scripts/office/schemas/microsoft/wml-2012.xsd +0 -67
  50. package/skills/engineering/pptx/scripts/office/schemas/microsoft/wml-2018.xsd +0 -14
  51. package/skills/engineering/pptx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +0 -20
  52. package/skills/engineering/pptx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +0 -13
  53. package/skills/engineering/pptx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +0 -4
  54. package/skills/engineering/pptx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +0 -8
  55. package/skills/engineering/pptx/scripts/office/soffice.py +0 -183
  56. package/skills/engineering/pptx/scripts/office/unpack.py +0 -132
  57. package/skills/engineering/pptx/scripts/office/validate.py +0 -111
  58. package/skills/engineering/pptx/scripts/office/validators/__init__.py +0 -15
  59. package/skills/engineering/pptx/scripts/office/validators/base.py +0 -847
  60. package/skills/engineering/pptx/scripts/office/validators/docx.py +0 -446
  61. package/skills/engineering/pptx/scripts/office/validators/pptx.py +0 -275
  62. package/skills/engineering/pptx/scripts/office/validators/redlining.py +0 -247
  63. package/skills/engineering/xlsx/SKILL.md +0 -320
  64. package/skills/engineering/xlsx/scripts/office/helpers/__init__.py +0 -0
  65. package/skills/engineering/xlsx/scripts/office/helpers/merge_runs.py +0 -199
  66. package/skills/engineering/xlsx/scripts/office/helpers/simplify_redlines.py +0 -197
  67. package/skills/engineering/xlsx/scripts/office/pack.py +0 -159
  68. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +0 -1499
  69. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +0 -146
  70. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +0 -1085
  71. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +0 -11
  72. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +0 -3081
  73. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +0 -23
  74. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +0 -185
  75. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +0 -287
  76. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +0 -1676
  77. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +0 -28
  78. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +0 -144
  79. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +0 -174
  80. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +0 -25
  81. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +0 -18
  82. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +0 -59
  83. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +0 -56
  84. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +0 -195
  85. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +0 -582
  86. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +0 -25
  87. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +0 -4439
  88. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +0 -570
  89. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +0 -509
  90. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +0 -12
  91. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +0 -108
  92. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +0 -96
  93. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +0 -3646
  94. package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +0 -116
  95. package/skills/engineering/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +0 -42
  96. package/skills/engineering/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +0 -50
  97. package/skills/engineering/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +0 -49
  98. package/skills/engineering/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +0 -33
  99. package/skills/engineering/xlsx/scripts/office/schemas/mce/mc.xsd +0 -75
  100. package/skills/engineering/xlsx/scripts/office/schemas/microsoft/wml-2010.xsd +0 -560
  101. package/skills/engineering/xlsx/scripts/office/schemas/microsoft/wml-2012.xsd +0 -67
  102. package/skills/engineering/xlsx/scripts/office/schemas/microsoft/wml-2018.xsd +0 -14
  103. package/skills/engineering/xlsx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +0 -20
  104. package/skills/engineering/xlsx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +0 -13
  105. package/skills/engineering/xlsx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +0 -4
  106. package/skills/engineering/xlsx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +0 -8
  107. package/skills/engineering/xlsx/scripts/office/soffice.py +0 -183
  108. package/skills/engineering/xlsx/scripts/office/unpack.py +0 -132
  109. package/skills/engineering/xlsx/scripts/office/validate.py +0 -111
  110. package/skills/engineering/xlsx/scripts/office/validators/__init__.py +0 -15
  111. package/skills/engineering/xlsx/scripts/office/validators/base.py +0 -847
  112. package/skills/engineering/xlsx/scripts/office/validators/docx.py +0 -446
  113. package/skills/engineering/xlsx/scripts/office/validators/pptx.py +0 -275
  114. package/skills/engineering/xlsx/scripts/office/validators/redlining.py +0 -247
  115. /package/skills/engineering/{pptx → officedocs}/editing.md +0 -0
  116. /package/skills/engineering/{pptx → officedocs}/pptxgenjs.md +0 -0
  117. /package/skills/engineering/{docx → officedocs}/scripts/__init__.py +0 -0
  118. /package/skills/engineering/{docx → officedocs}/scripts/accept_changes.py +0 -0
  119. /package/skills/engineering/{pptx → officedocs}/scripts/add_slide.py +0 -0
  120. /package/skills/engineering/{pptx → officedocs}/scripts/clean.py +0 -0
  121. /package/skills/engineering/{docx → officedocs}/scripts/comment.py +0 -0
  122. /package/skills/engineering/{docx → officedocs}/scripts/office/helpers/__init__.py +0 -0
  123. /package/skills/engineering/{docx → officedocs}/scripts/office/helpers/merge_runs.py +0 -0
  124. /package/skills/engineering/{docx → officedocs}/scripts/office/helpers/simplify_redlines.py +0 -0
  125. /package/skills/engineering/{docx → officedocs}/scripts/office/pack.py +0 -0
  126. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +0 -0
  127. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +0 -0
  128. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +0 -0
  129. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +0 -0
  130. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +0 -0
  131. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +0 -0
  132. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +0 -0
  133. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +0 -0
  134. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +0 -0
  135. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +0 -0
  136. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +0 -0
  137. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +0 -0
  138. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +0 -0
  139. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +0 -0
  140. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +0 -0
  141. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +0 -0
  142. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +0 -0
  143. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +0 -0
  144. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +0 -0
  145. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +0 -0
  146. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +0 -0
  147. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +0 -0
  148. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +0 -0
  149. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +0 -0
  150. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +0 -0
  151. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +0 -0
  152. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +0 -0
  153. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +0 -0
  154. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +0 -0
  155. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +0 -0
  156. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +0 -0
  157. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/mce/mc.xsd +0 -0
  158. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/microsoft/wml-2010.xsd +0 -0
  159. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/microsoft/wml-2012.xsd +0 -0
  160. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/microsoft/wml-2018.xsd +0 -0
  161. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/microsoft/wml-cex-2018.xsd +0 -0
  162. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/microsoft/wml-cid-2016.xsd +0 -0
  163. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +0 -0
  164. /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/microsoft/wml-symex-2015.xsd +0 -0
  165. /package/skills/engineering/{docx → officedocs}/scripts/office/soffice.py +0 -0
  166. /package/skills/engineering/{docx → officedocs}/scripts/office/unpack.py +0 -0
  167. /package/skills/engineering/{docx → officedocs}/scripts/office/validate.py +0 -0
  168. /package/skills/engineering/{docx → officedocs}/scripts/office/validators/__init__.py +0 -0
  169. /package/skills/engineering/{docx → officedocs}/scripts/office/validators/base.py +0 -0
  170. /package/skills/engineering/{docx → officedocs}/scripts/office/validators/docx.py +0 -0
  171. /package/skills/engineering/{docx → officedocs}/scripts/office/validators/pptx.py +0 -0
  172. /package/skills/engineering/{docx → officedocs}/scripts/office/validators/redlining.py +0 -0
  173. /package/skills/engineering/{xlsx → officedocs}/scripts/recalc.py +0 -0
  174. /package/skills/engineering/{docx → officedocs}/scripts/templates/comments.xml +0 -0
  175. /package/skills/engineering/{docx → officedocs}/scripts/templates/commentsExtended.xml +0 -0
  176. /package/skills/engineering/{docx → officedocs}/scripts/templates/commentsExtensible.xml +0 -0
  177. /package/skills/engineering/{docx → officedocs}/scripts/templates/commentsIds.xml +0 -0
  178. /package/skills/engineering/{docx → officedocs}/scripts/templates/people.xml +0 -0
  179. /package/skills/engineering/{pptx → officedocs}/scripts/thumbnail.py +0 -0
@@ -1,617 +0,0 @@
1
- ---
2
- name: docx
3
- description: "当用户需要创建、读取、编辑或操作Word文档(.docx文件)时使用本技能。触发场景包括:任何提及'Word doc'、'word document'、'.docx'的内容,或生成带目录、标题、页码、信头格式的专业文档的需求。也适用于从.docx文件提取或重组内容、在文档中插入或替换图片、在Word文件中执行查找替换、处理修订或评论、或将内容转换为精美Word文档的场景。如果用户要求生成Word或.docx格式的'报告'、'备忘录'、'信件'、'模板'或类似交付物,使用本技能。请勿用于PDF、电子表格、Google Docs或与文档生成无关的通用编码任务。"
4
- license: 专有。LICENSE.txt包含完整条款
5
- ---
6
-
7
- # DOCX创建、编辑与分析
8
-
9
- ## 概述
10
-
11
- .docx文件是包含XML文件的ZIP压缩包。
12
-
13
- ## 快速参考
14
-
15
- | 任务 | 实现方式 |
16
- | - | - |
17
- | 读取/分析内容 | `pandoc` 或解包获取原始XML |
18
- | 创建新文档 | 使用 `docx-js` - 参考下方创建新文档部分 |
19
- | 编辑现有文档 | 解包 → 编辑XML → 重新打包 - 参考下方编辑现有文档部分 |
20
-
21
- ### 将.doc转换为.docx
22
-
23
- 旧版`.doc`文件必须先转换才能编辑:
24
-
25
- ```bash
26
- python scripts/office/soffice.py --headless --convert-to docx document.doc
27
- ```
28
-
29
- ### 读取内容
30
-
31
- ```bash
32
- # 提取包含修订的文本
33
- pandoc --track-changes=all document.docx -o output.md
34
-
35
- # 访问原始XML
36
- python scripts/office/unpack.py document.docx unpacked/
37
- ```
38
-
39
- ### 转换为图片
40
-
41
- ```bash
42
- python scripts/office/soffice.py --headless --convert-to pdf document.docx
43
- pdftoppm -jpeg -r 150 document.pdf page
44
- ```
45
-
46
- ### 接受所有修订
47
-
48
- 生成已接受所有修订的干净文档(需要LibreOffice):
49
-
50
- ```bash
51
- python scripts/accept_changes.py input.docx output.docx
52
- ```
53
-
54
- ---
55
-
56
- ## 创建新文档
57
-
58
- 使用JavaScript生成.docx文件,然后验证。安装依赖:`npm install -g docx`
59
-
60
- ### 初始化
61
-
62
- ```javascript
63
- const { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell, ImageRun,
64
- Header, Footer, AlignmentType, PageOrientation, LevelFormat, ExternalHyperlink,
65
- InternalHyperlink, Bookmark, FootnoteReferenceRun, PositionalTab,
66
- PositionalTabAlignment, PositionalTabRelativeTo, PositionalTabLeader,
67
- TabStopType, TabStopPosition, Column, SectionType,
68
- TableOfContents, HeadingLevel, BorderStyle, WidthType, ShadingType,
69
- VerticalAlign, PageNumber, PageBreak } = require('docx');
70
-
71
- const doc = new Document({ sections: [{ children: [/* 内容 */] }] });
72
- Packer.toBuffer(doc).then(buffer => fs.writeFileSync("doc.docx", buffer));
73
- ```
74
-
75
- ### 验证
76
-
77
- 创建文件后进行验证。如果验证失败,解包、修复XML、重新打包。
78
-
79
- ```bash
80
- python scripts/office/validate.py doc.docx
81
- ```
82
-
83
- ### 页面尺寸
84
-
85
- ```javascript
86
- // 重要提示: docx-js默认使用A4,而非美国Letter尺寸
87
- // 始终显式设置页面尺寸以获得一致结果
88
- sections: [{
89
- properties: {
90
- page: {
91
- size: {
92
- width: 12240, // 8.5英寸,单位DXA
93
- height: 15840 // 11英寸,单位DXA
94
- },
95
- margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } // 1英寸边距
96
- }
97
- },
98
- children: [/* 内容 */]
99
- }]
100
- ```
101
-
102
- **常用页面尺寸(DXA单位,1440 DXA = 1英寸):**
103
-
104
- | 纸张类型 | 宽度 | 高度 | 内容宽度(1英寸边距) |
105
- | ------- | ------- | -------- | ------------------------ |
106
- | US Letter | 12,240 | 15,840 | 9,360 |
107
- | A4(默认) | 11,906 | 16,838 | 9,026 |
108
-
109
- **横向布局:** docx-js会内部交换宽度/高度,因此传入纵向尺寸让它自动处理交换:
110
-
111
- ```javascript
112
- size: {
113
- width: 12240, // 将短边作为width传入
114
- height: 15840, // 将长边作为height传入
115
- orientation: PageOrientation.LANDSCAPE // docx-js会在XML中交换它们
116
- },
117
- // 内容宽度 = 15840 - 左边距 - 右边距(使用长边)
118
- ```
119
-
120
- ### 样式(覆盖内置标题样式)
121
-
122
- 使用Arial作为默认字体(通用支持)。标题保持黑色以提高可读性。
123
-
124
- ```javascript
125
- const doc = new Document({
126
- styles: {
127
- default: { document: { run: { font: "Arial", size: 24 } } }, // 默认12pt
128
- paragraphStyles: [
129
- // 重要提示: 使用精确的ID覆盖内置样式
130
- { id: "Heading1", name: "Heading 1", basedOn: "Normal", next: "Normal", quickFormat: true,
131
- run: { size: 32, bold: true, font: "Arial" },
132
- paragraph: { spacing: { before: 240, after: 240 }, outlineLevel: 0 } }, // outlineLevel是目录必需的
133
- { id: "Heading2", name: "Heading 2", basedOn: "Normal", next: "Normal", quickFormat: true,
134
- run: { size: 28, bold: true, font: "Arial" },
135
- paragraph: { spacing: { before: 180, after: 180 }, outlineLevel: 1 } },
136
- ]
137
- },
138
- sections: [{
139
- children: [
140
- new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("标题")] }),
141
- ]
142
- }]
143
- });
144
- ```
145
-
146
- ### 列表(切勿使用Unicode项目符号)
147
-
148
- ```javascript
149
- // ❌ 错误 - 切勿手动插入项目符号字符
150
- new Paragraph({ children: [new TextRun("• 项目")] }) // 错误
151
- new Paragraph({ children: [new TextRun("\u2022 项目")] }) // 错误
152
-
153
- // ✅ 正确 - 使用带LevelFormat.BULLET的编号配置
154
- const doc = new Document({
155
- numbering: {
156
- config: [
157
- { reference: "bullets",
158
- levels: [{ level: 0, format: LevelFormat.BULLET, text: "•", alignment: AlignmentType.LEFT,
159
- style: { paragraph: { indent: { left: 720, hanging: 360 } } } }] },
160
- { reference: "numbers",
161
- levels: [{ level: 0, format: LevelFormat.DECIMAL, text: "%1.", alignment: AlignmentType.LEFT,
162
- style: { paragraph: { indent: { left: 720, hanging: 360 } } } }] },
163
- ]
164
- },
165
- sections: [{
166
- children: [
167
- new Paragraph({ numbering: { reference: "bullets", level: 0 },
168
- children: [new TextRun("项目符号项")] }),
169
- new Paragraph({ numbering: { reference: "numbers", level: 0 },
170
- children: [new TextRun("编号项")] }),
171
- ]
172
- }]
173
- });
174
-
175
- // ⚠️ 每个reference创建独立的编号序列
176
- // 相同reference = 编号连续 (1,2,3 接着 4,5,6)
177
- // 不同reference = 编号重新开始 (1,2,3 接着 1,2,3)
178
- ```
179
-
180
- ### 表格
181
-
182
- **重要提示:表格需要双重宽度设置** - 同时设置表格的`columnWidths`和每个单元格的`width`。缺少任意一个,表格在某些平台会渲染错误。
183
-
184
- ```javascript
185
- // 重要提示: 始终设置表格宽度以保证渲染一致
186
- // 重要提示: 使用ShadingType.CLEAR(而非SOLID)避免黑色背景
187
- const border = { style: BorderStyle.SINGLE, size: 1, color: "CCCCCC" };
188
- const borders = { top: border, bottom: border, left: border, right: border };
189
-
190
- new Table({
191
- width: { size: 9360, type: WidthType.DXA }, // 始终使用DXA(百分比在Google Docs中失效)
192
- columnWidths: [4680, 4680], // 总和必须等于表格宽度(DXA:1440 = 1英寸)
193
- rows: [
194
- new TableRow({
195
- children: [
196
- new TableCell({
197
- borders,
198
- width: { size: 4680, type: WidthType.DXA }, // 每个单元格也要设置
199
- shading: { fill: "D5E8F0", type: ShadingType.CLEAR }, // CLEAR而非SOLID
200
- margins: { top: 80, bottom: 80, left: 120, right: 120 }, // 单元格内边距(内部,不增加宽度)
201
- children: [new Paragraph({ children: [new TextRun("单元格")] })]
202
- })
203
- ]
204
- })
205
- ]
206
- })
207
- ```
208
-
209
- **表格宽度计算:**
210
-
211
- 始终使用`WidthType.DXA` — `WidthType.PERCENTAGE`在Google Docs中失效。
212
-
213
- ```javascript
214
- // 表格宽度 = columnWidths之和 = 内容宽度
215
- // 1英寸边距的US Letter: 12240 - 2880 = 9360 DXA
216
- width: { size: 9360, type: WidthType.DXA },
217
- columnWidths: [7000, 2360] // 总和必须等于表格宽度
218
- ```
219
-
220
- **宽度规则:**
221
-
222
- - **始终使用`WidthType.DXA`** — 切勿使用`WidthType.PERCENTAGE`(与Google Docs不兼容)
223
- - 表格宽度必须等于`columnWidths`之和
224
- - 单元格`width`必须与对应`columnWidth`匹配
225
- - 单元格`margins`是内部内边距 - 会减少内容区域,不会增加单元格宽度
226
- - 通栏表格:使用内容宽度(页面宽度减去左右边距)
227
-
228
- ### 图片
229
-
230
- ```javascript
231
- // 重要提示: type参数是必需的
232
- new Paragraph({
233
- children: [new ImageRun({
234
- type: "png", // 必需: png, jpg, jpeg, gif, bmp, svg
235
- data: fs.readFileSync("image.png"),
236
- transformation: { width: 200, height: 150 },
237
- altText: { title: "标题", description: "描述", name: "名称" } // 三个属性都必需
238
- })]
239
- })
240
- ```
241
-
242
- ### 分页符
243
-
244
- ```javascript
245
- // 重要提示: PageBreak必须放在Paragraph内部
246
- new Paragraph({ children: [new PageBreak()] })
247
-
248
- // 或使用pageBreakBefore
249
- new Paragraph({ pageBreakBefore: true, children: [new TextRun("新页面")] })
250
- ```
251
-
252
- ### 超链接
253
-
254
- ```javascript
255
- // 外部链接
256
- new Paragraph({
257
- children: [new ExternalHyperlink({
258
- children: [new TextRun({ text: "点击这里", style: "Hyperlink" })],
259
- link: "https://example.com",
260
- })]
261
- })
262
-
263
- // 内部链接(书签 + 引用)
264
- // 1. 在目标位置创建书签
265
- new Paragraph({ heading: HeadingLevel.HEADING_1, children: [
266
- new Bookmark({ id: "chapter1", children: [new TextRun("第一章")] }),
267
- ]})
268
- // 2. 链接到书签
269
- new Paragraph({ children: [new InternalHyperlink({
270
- children: [new TextRun({ text: "查看第一章", style: "Hyperlink" })],
271
- anchor: "chapter1",
272
- })]})
273
- ```
274
-
275
- ### 脚注
276
-
277
- ```javascript
278
- const doc = new Document({
279
- footnotes: {
280
- 1: { children: [new Paragraph("来源:2024年度报告")] },
281
- 2: { children: [new Paragraph("方法学见附录")] },
282
- },
283
- sections: [{
284
- children: [new Paragraph({
285
- children: [
286
- new TextRun("收入增长15%"),
287
- new FootnoteReferenceRun(1),
288
- new TextRun(" 使用调整后指标"),
289
- new FootnoteReferenceRun(2),
290
- ],
291
- })]
292
- }]
293
- });
294
- ```
295
-
296
- ### 制表位
297
-
298
- ```javascript
299
- // 同一行右对齐文本(例如标题右侧的日期)
300
- new Paragraph({
301
- children: [
302
- new TextRun("公司名称"),
303
- new TextRun("\t2025年1月"),
304
- ],
305
- tabStops: [{ type: TabStopType.RIGHT, position: TabStopPosition.MAX }],
306
- })
307
-
308
- // 点引导符(例如目录样式)
309
- new Paragraph({
310
- children: [
311
- new TextRun("简介"),
312
- new TextRun({ children: [
313
- new PositionalTab({
314
- alignment: PositionalTabAlignment.RIGHT,
315
- relativeTo: PositionalTabRelativeTo.MARGIN,
316
- leader: PositionalTabLeader.DOT,
317
- }),
318
- "3",
319
- ]}),
320
- ],
321
- })
322
- ```
323
-
324
- ### 多列布局
325
-
326
- ```javascript
327
- // 等宽列
328
- sections: [{
329
- properties: {
330
- column: {
331
- count: 2, // 列数
332
- space: 720, // 列间距,单位DXA(720 = 0.5英寸)
333
- equalWidth: true,
334
- separate: true, // 列之间显示竖线
335
- },
336
- },
337
- children: [/* 内容会自动跨列流动 */]
338
- }]
339
-
340
- // 自定义宽度列(equalWidth必须为false)
341
- sections: [{
342
- properties: {
343
- column: {
344
- equalWidth: false,
345
- children: [
346
- new Column({ width: 5400, space: 720 }),
347
- new Column({ width: 3240 }),
348
- ],
349
- },
350
- },
351
- children: [/* 内容 */]
352
- }]
353
- ```
354
-
355
- 使用`type: SectionType.NEXT_COLUMN`的新节强制列分页。
356
-
357
- ### 目录
358
-
359
- ```javascript
360
- // 重要提示: 标题必须仅使用HeadingLevel - 不能使用自定义样式
361
- new TableOfContents("目录", { hyperlink: true, headingStyleRange: "1-3" })
362
- ```
363
-
364
- ### 页眉/页脚
365
-
366
- ```javascript
367
- sections: [{
368
- properties: {
369
- page: { margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } } // 1440 = 1英寸
370
- },
371
- headers: {
372
- default: new Header({ children: [new Paragraph({ children: [new TextRun("页眉")] })] })
373
- },
374
- footers: {
375
- default: new Footer({ children: [new Paragraph({
376
- children: [new TextRun("第 "), new TextRun({ children: [PageNumber.CURRENT] }), new TextRun(" 页")]
377
- })] })
378
- },
379
- children: [/* 内容 */]
380
- }]
381
- ```
382
-
383
- ### docx-js重要规则
384
-
385
- - **显式设置页面尺寸** - docx-js默认使用A4;美国文档使用US Letter(12240 x 15840 DXA)
386
- - **横向布局:传入纵向尺寸** - docx-js会内部交换宽度/高度;将短边作为`width`,长边作为`height`,并设置`orientation: PageOrientation.LANDSCAPE`
387
- - **切勿使用`\n`** - 使用独立的Paragraph元素
388
- - **切勿使用Unicode项目符号** - 使用带编号配置的`LevelFormat.BULLET`
389
- - **PageBreak必须放在Paragraph内** - 单独使用会生成无效XML
390
- - **ImageRun需要`type`参数** - 始终指定png/jpg等类型
391
- - **始终使用DXA设置表格`width`** - 切勿使用`WidthType.PERCENTAGE`(在Google Docs中失效)
392
- - **表格需要双重宽度设置** - `columnWidths`数组和单元格`width`,两者必须匹配
393
- - **表格宽度 = columnWidths之和** - 使用DXA时确保数值完全相加
394
- - **始终添加单元格边距** - 使用`margins: { top: 80, bottom: 80, left: 120, right: 120 }`获得可读的内边距
395
- - **使用`ShadingType.CLEAR`** - 表格底纹切勿使用SOLID
396
- - **切勿将表格用作分隔线/规则线** - 单元格有最小高度,会渲染为空框(包括页眉/页脚中的表格);改为在Paragraph上使用`border: { bottom: { style: BorderStyle.SINGLE, size: 6, color: "2E75B6", space: 1 } }`。两栏页脚使用制表位(参考制表位部分),而非表格
397
- - **目录仅支持HeadingLevel** - 标题段落不能使用自定义样式
398
- - **覆盖内置样式** - 使用精确ID:"Heading1"、"Heading2"等
399
- - **包含`outlineLevel`** - 目录必需(H1为0,H2为1,依此类推)
400
-
401
- ---
402
-
403
- ## 编辑现有文档
404
-
405
- **按顺序执行全部3个步骤。**
406
-
407
- ### 步骤1:解包
408
-
409
- ```bash
410
- python scripts/office/unpack.py document.docx unpacked/
411
- ```
412
-
413
- 提取XML、格式化打印、合并相邻文本块,并将智能引号转换为XML实体(`“`等)以确保编辑后保留。使用`--merge-runs false`跳过文本块合并。
414
-
415
- ### 步骤2:编辑XML
416
-
417
- 编辑`unpacked/word/`中的文件。参考下方XML参考部分的模式。
418
-
419
- **修订和评论默认使用"Opencode"作为作者**,除非用户明确要求使用其他名称。
420
-
421
- **直接使用Edit工具进行字符串替换。不要编写Python脚本。** 脚本会引入不必要的复杂度。Edit工具会显示确切的替换内容。
422
-
423
- **重要提示:新内容使用智能引号。** 添加带引号或撇号的文本时,使用XML实体生成智能引号:
424
-
425
- ```xml
426
- <!-- 使用这些实体实现专业排版 -->
427
- <w:t>这里&#x2019;有一个引号:&#x201C;你好&#x201D;</w:t>
428
- ```
429
-
430
- | 实体 | 字符 |
431
- | -------- | ----------- |
432
- | `&#x2018;` | ‘(左单引号) |
433
- | `&#x2019;` | ’(右单引号/撇号) |
434
- | `&#x201C;` | “(左双引号) |
435
- | `&#x201D;` | ”(右双引号) |
436
-
437
- **添加评论:** 使用`comment.py`处理多个XML文件的模板(文本必须是预转义的XML):
438
-
439
- ```bash
440
- python scripts/comment.py unpacked/ 0 "包含&amp;和&#x2019;的评论文本"
441
- python scripts/comment.py unpacked/ 1 "回复文本" --parent 0 # 回复评论0
442
- python scripts/comment.py unpacked/ 0 "文本" --author "自定义作者" # 自定义作者名称
443
- ```
444
-
445
- 然后在document.xml中添加标记(参考XML参考中的评论部分)。
446
-
447
- ### 步骤3:打包
448
-
449
- ```bash
450
- python scripts/office/pack.py unpacked/ output.docx --original document.docx
451
- ```
452
-
453
- 执行自动修复验证、压缩XML并生成DOCX。使用`--validate false`跳过验证。
454
-
455
- **自动修复会处理:**
456
-
457
- - `durableId` >= 0x7FFFFFFF(重新生成有效ID)
458
- - 带空白的`<w:t>`缺少`xml:space="preserve"`的问题
459
-
460
- **自动修复不会处理:**
461
-
462
- - 格式错误的XML、无效元素嵌套、缺少关联、架构违规
463
-
464
- ### 常见陷阱
465
-
466
- - **替换整个`<w:r>`元素**:添加修订时,将整个`<w:r>...</w:r>`块替换为同级的`<w:del>...<w:ins>...`。不要在文本块内部注入修订标签。
467
- - **保留`<w:rPr>`格式**:将原始文本块的`<w:rPr>`块复制到修订文本块中,以保持粗体、字体大小等格式。
468
-
469
- ---
470
-
471
- ## XML参考
472
-
473
- ### 架构合规性
474
-
475
- - **`<w:pPr>`中的元素顺序**:`<w:pStyle>`、`<w:numPr>`、`<w:spacing>`、`<w:ind>`、`<w:jc>`、最后是`<w:rPr>`
476
- - **空白处理**:带前后空格的`<w:t>`添加`xml:space="preserve"`
477
- - **RSIDs**:必须是8位十六进制(例如`00AB1234`)
478
-
479
- ### 修订
480
-
481
- **插入:**
482
-
483
- ```xml
484
- <w:ins w:id="1" w:author="Opencode" w:date="2025-01-01T00:00:00Z">
485
- <w:r><w:t>插入的文本</w:t></w:r>
486
- </w:ins>
487
- ```
488
-
489
- **删除:**
490
-
491
- ```xml
492
- <w:del w:id="2" w:author="Opencode" w:date="2025-01-01T00:00:00Z">
493
- <w:r><w:delText>删除的文本</w:delText></w:r>
494
- </w:del>
495
- ```
496
-
497
- **`<w:del>`内部**:使用`<w:delText>`替代`<w:t>`,使用`<w:delInstrText>`替代`<w:instrText>`。
498
-
499
- **最小化编辑** - 仅标记更改部分:
500
-
501
- ```xml
502
- <!-- 将"30天"改为"60天" -->
503
- <w:r><w:t>期限为 </w:t></w:r>
504
- <w:del w:id="1" w:author="Opencode" w:date="...">
505
- <w:r><w:delText>30</w:delText></w:r>
506
- </w:del>
507
- <w:ins w:id="2" w:author="Opencode" w:date="...">
508
- <w:r><w:t>60</w:t></w:r>
509
- </w:ins>
510
- <w:r><w:t> 天。</w:t></w:r>
511
- ```
512
-
513
- **删除整个段落/列表项** - 移除段落的所有内容时,也要将段落标记标记为已删除,使其与下一段落合并。在`<w:pPr><w:rPr>`中添加`<w:del/>`:
514
-
515
- ```xml
516
- <w:p>
517
- <w:pPr>
518
- <w:numPr>...</w:numPr> <!-- 列表编号(如果存在) -->
519
- <w:rPr>
520
- <w:del w:id="1" w:author="Opencode" w:date="2025-01-01T00:00:00Z"/>
521
- </w:rPr>
522
- </w:pPr>
523
- <w:del w:id="2" w:author="Opencode" w:date="2025-01-01T00:00:00Z">
524
- <w:r><w:delText>正在删除的整个段落内容...</w:delText></w:r>
525
- </w:del>
526
- </w:p>
527
- ```
528
-
529
- 如果`<w:pPr><w:rPr>`中缺少`<w:del/>`,接受修订后会留下空段落/列表项。
530
-
531
- **拒绝其他作者的插入** - 将删除嵌套在他们的插入中:
532
-
533
- ```xml
534
- <w:ins w:author="Jane" w:id="5">
535
- <w:del w:author="Opencode" w:id="10">
536
- <w:r><w:delText>他们插入的文本</w:delText></w:r>
537
- </w:del>
538
- </w:ins>
539
- ```
540
-
541
- **恢复其他作者的删除** - 在后面添加插入(不要修改他们的删除):
542
-
543
- ```xml
544
- <w:del w:author="Jane" w:id="5">
545
- <w:r><w:delText>删除的文本</w:delText></w:r>
546
- </w:del>
547
- <w:ins w:author="Opencode" w:id="10">
548
- <w:r><w:t>删除的文本</w:t></w:r>
549
- </w:ins>
550
- ```
551
-
552
- ### 评论
553
-
554
- 运行`comment.py`后(参考步骤2),在document.xml中添加标记。回复使用`--parent`参数并将标记嵌套在父标记内。
555
-
556
- **重要提示:`<w:commentRangeStart>`和`<w:commentRangeEnd>`是`<w:r>`的同级元素,绝不能放在`<w:r>`内部。**
557
-
558
- ```xml
559
- <!-- 评论标记是w:p的直接子元素,绝不能放在w:r内部 -->
560
- <w:commentRangeStart w:id="0"/>
561
- <w:del w:id="1" w:author="Opencode" w:date="2025-01-01T00:00:00Z">
562
- <w:r><w:delText>删除的</w:delText></w:r>
563
- </w:del>
564
- <w:r><w:t> 更多文本</w:t></w:r>
565
- <w:commentRangeEnd w:id="0"/>
566
- <w:r><w:rPr><w:rStyle w:val="CommentReference"/></w:rPr><w:commentReference w:id="0"/></w:r>
567
-
568
- <!-- 评论0包含嵌套的回复1 -->
569
- <w:commentRangeStart w:id="0"/>
570
- <w:commentRangeStart w:id="1"/>
571
- <w:r><w:t>文本</w:t></w:r>
572
- <w:commentRangeEnd w:id="1"/>
573
- <w:commentRangeEnd w:id="0"/>
574
- <w:r><w:rPr><w:rStyle w:val="CommentReference"/></w:rPr><w:commentReference w:id="0"/></w:r>
575
- <w:r><w:rPr><w:rStyle w:val="CommentReference"/></w:rPr><w:commentReference w:id="1"/></w:r>
576
- ```
577
-
578
- ### 图片生成
579
-
580
- 1. 将图片文件添加到`word/media/`
581
- 2. 在`word/_rels/document.xml.rels`中添加关联:
582
-
583
- ```xml
584
- <Relationship Id="rId5" Type=".../image" Target="media/image1.png"/>
585
- ```
586
-
587
- 1. 在`[Content_Types].xml`中添加内容类型:
588
-
589
- ```xml
590
- <Default Extension="png" ContentType="image/png"/>
591
- ```
592
-
593
- 1. 在document.xml中引用:
594
-
595
- ```xml
596
- <w:drawing>
597
- <wp:inline>
598
- <wp:extent cx="914400" cy="914400"/> <!-- EMU单位:914400 = 1英寸 -->
599
- <a:graphic>
600
- <a:graphicData uri=".../picture">
601
- <pic:pic>
602
- <pic:blipFill><a:blip r:embed="rId5"/></pic:blipFill>
603
- </pic:pic>
604
- </a:graphicData>
605
- </a:graphic>
606
- </wp:inline>
607
- </w:drawing>
608
- ```
609
-
610
- ---
611
-
612
- ## 依赖
613
-
614
- - **pandoc**:文本提取
615
- - **docx**:`npm install -g docx`(新建文档)
616
- - **LibreOffice**:PDF转换(通过`scripts/office/soffice.py`为沙箱环境自动配置)
617
- - **Poppler**:`pdftoppm`用于图片转换