{
  "schemaVersion": "1.0",
  "item": {
    "slug": "docx-cn",
    "name": "Docx Cn",
    "source": "tencent",
    "type": "skill",
    "category": "内容创作",
    "sourceUrl": "https://clawhub.ai/guohongbin-git/docx-cn",
    "canonicalUrl": "https://clawhub.ai/guohongbin-git/docx-cn",
    "targetPlatform": "OpenClaw"
  },
  "install": {
    "downloadMode": "redirect",
    "downloadUrl": "/downloads/docx-cn",
    "sourceDownloadUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=docx-cn",
    "sourcePlatform": "tencent",
    "targetPlatform": "OpenClaw",
    "installMethod": "Manual import",
    "extraction": "Extract archive",
    "prerequisites": [
      "OpenClaw"
    ],
    "packageFormat": "ZIP package",
    "includedAssets": [
      "LICENSE.txt",
      "SKILL.md",
      "_meta.json",
      "scripts/__init__.py",
      "scripts/accept_changes.py",
      "scripts/comment.py"
    ],
    "primaryDoc": "SKILL.md",
    "quickSetup": [
      "Download the package from Yavira.",
      "Extract the archive and review SKILL.md first.",
      "Import or place the package into your OpenClaw setup."
    ],
    "agentAssist": {
      "summary": "Hand the extracted package to your coding agent with a concrete install brief instead of figuring it out manually.",
      "steps": [
        "Download the package from Yavira.",
        "Extract it into a folder your agent can access.",
        "Paste one of the prompts below and point your agent at the extracted folder."
      ],
      "prompts": [
        {
          "label": "New install",
          "body": "I downloaded a skill package from Yavira. Read SKILL.md from the extracted folder and install it by following the included instructions. Tell me what you changed and call out any manual steps you could not complete."
        },
        {
          "label": "Upgrade existing",
          "body": "I downloaded an updated skill package from Yavira. Read SKILL.md from the extracted folder, compare it with my current installation, and upgrade it while preserving any custom configuration unless the package docs explicitly say otherwise. Summarize what changed and any follow-up checks I should run."
        }
      ]
    },
    "sourceHealth": {
      "source": "tencent",
      "status": "healthy",
      "reason": "direct_download_ok",
      "recommendedAction": "download",
      "checkedAt": "2026-04-23T16:43:11.935Z",
      "expiresAt": "2026-04-30T16:43:11.935Z",
      "httpStatus": 200,
      "finalUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=4claw-imageboard",
      "contentType": "application/zip",
      "probeMethod": "head",
      "details": {
        "probeUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=4claw-imageboard",
        "contentDisposition": "attachment; filename=\"4claw-imageboard-1.0.1.zip\"",
        "redirectLocation": null,
        "bodySnippet": null
      },
      "scope": "source",
      "summary": "Source download looks usable.",
      "detail": "Yavira can redirect you to the upstream package for this source.",
      "primaryActionLabel": "Download for OpenClaw",
      "primaryActionHref": "/downloads/docx-cn"
    },
    "validation": {
      "installChecklist": [
        "Use the Yavira download entry.",
        "Review SKILL.md after the package is downloaded.",
        "Confirm the extracted package contains the expected setup assets."
      ],
      "postInstallChecks": [
        "Confirm the extracted package includes the expected docs or setup files.",
        "Validate the skill or prompts are available in your target agent workspace.",
        "Capture any manual follow-up steps the agent could not complete."
      ]
    },
    "downloadPageUrl": "https://openagent3.xyz/downloads/docx-cn",
    "agentPageUrl": "https://openagent3.xyz/skills/docx-cn/agent",
    "manifestUrl": "https://openagent3.xyz/skills/docx-cn/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/docx-cn/agent.md"
  },
  "agentAssist": {
    "summary": "Hand the extracted package to your coding agent with a concrete install brief instead of figuring it out manually.",
    "steps": [
      "Download the package from Yavira.",
      "Extract it into a folder your agent can access.",
      "Paste one of the prompts below and point your agent at the extracted folder."
    ],
    "prompts": [
      {
        "label": "New install",
        "body": "I downloaded a skill package from Yavira. Read SKILL.md from the extracted folder and install it by following the included instructions. Tell me what you changed and call out any manual steps you could not complete."
      },
      {
        "label": "Upgrade existing",
        "body": "I downloaded an updated skill package from Yavira. Read SKILL.md from the extracted folder, compare it with my current installation, and upgrade it while preserving any custom configuration unless the package docs explicitly say otherwise. Summarize what changed and any follow-up checks I should run."
      }
    ]
  },
  "documentation": {
    "source": "clawhub",
    "primaryDoc": "SKILL.md",
    "sections": [
      {
        "title": "Overview",
        "body": "A .docx file is a ZIP archive containing XML files."
      },
      {
        "title": "Quick Reference",
        "body": "TaskApproachRead/analyze contentpandoc or unpack for raw XMLCreate new documentUse docx-js - see Creating New Documents belowEdit existing documentUnpack → edit XML → repack - see Editing Existing Documents below"
      },
      {
        "title": "Converting .doc to .docx",
        "body": "Legacy .doc files must be converted before editing:\n\npython scripts/office/soffice.py --headless --convert-to docx document.doc"
      },
      {
        "title": "Reading Content",
        "body": "# Text extraction with tracked changes\npandoc --track-changes=all document.docx -o output.md\n\n# Raw XML access\npython scripts/office/unpack.py document.docx unpacked/"
      },
      {
        "title": "Converting to Images",
        "body": "python scripts/office/soffice.py --headless --convert-to pdf document.docx\npdftoppm -jpeg -r 150 document.pdf page"
      },
      {
        "title": "Accepting Tracked Changes",
        "body": "To produce a clean document with all tracked changes accepted (requires LibreOffice):\n\npython scripts/accept_changes.py input.docx output.docx"
      },
      {
        "title": "Creating New Documents",
        "body": "Generate .docx files with JavaScript, then validate. Install: npm install -g docx"
      },
      {
        "title": "Setup",
        "body": "const { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell, ImageRun,\n        Header, Footer, AlignmentType, PageOrientation, LevelFormat, ExternalHyperlink,\n        TableOfContents, HeadingLevel, BorderStyle, WidthType, ShadingType,\n        VerticalAlign, PageNumber, PageBreak } = require('docx');\n\nconst doc = new Document({ sections: [{ children: [/* content */] }] });\nPacker.toBuffer(doc).then(buffer => fs.writeFileSync(\"doc.docx\", buffer));"
      },
      {
        "title": "Validation",
        "body": "After creating the file, validate it. If validation fails, unpack, fix the XML, and repack.\n\npython scripts/office/validate.py doc.docx"
      },
      {
        "title": "Page Size",
        "body": "// CRITICAL: docx-js defaults to A4, not US Letter\n// Always set page size explicitly for consistent results\nsections: [{\n  properties: {\n    page: {\n      size: {\n        width: 12240,   // 8.5 inches in DXA\n        height: 15840   // 11 inches in DXA\n      },\n      margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } // 1 inch margins\n    }\n  },\n  children: [/* content */]\n}]\n\nCommon page sizes (DXA units, 1440 DXA = 1 inch):\n\nPaperWidthHeightContent Width (1\" margins)US Letter12,24015,8409,360A4 (default)11,90616,8389,026\n\nLandscape orientation: docx-js swaps width/height internally, so pass portrait dimensions and let it handle the swap:\n\nsize: {\n  width: 12240,   // Pass SHORT edge as width\n  height: 15840,  // Pass LONG edge as height\n  orientation: PageOrientation.LANDSCAPE  // docx-js swaps them in the XML\n},\n// Content width = 15840 - left margin - right margin (uses the long edge)"
      },
      {
        "title": "Styles (Override Built-in Headings)",
        "body": "Use Arial as the default font (universally supported). Keep titles black for readability.\n\nconst doc = new Document({\n  styles: {\n    default: { document: { run: { font: \"Arial\", size: 24 } } }, // 12pt default\n    paragraphStyles: [\n      // IMPORTANT: Use exact IDs to override built-in styles\n      { id: \"Heading1\", name: \"Heading 1\", basedOn: \"Normal\", next: \"Normal\", quickFormat: true,\n        run: { size: 32, bold: true, font: \"Arial\" },\n        paragraph: { spacing: { before: 240, after: 240 }, outlineLevel: 0 } }, // outlineLevel required for TOC\n      { id: \"Heading2\", name: \"Heading 2\", basedOn: \"Normal\", next: \"Normal\", quickFormat: true,\n        run: { size: 28, bold: true, font: \"Arial\" },\n        paragraph: { spacing: { before: 180, after: 180 }, outlineLevel: 1 } },\n    ]\n  },\n  sections: [{\n    children: [\n      new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun(\"Title\")] }),\n    ]\n  }]\n});"
      },
      {
        "title": "Lists (NEVER use unicode bullets)",
        "body": "// ❌ WRONG - never manually insert bullet characters\nnew Paragraph({ children: [new TextRun(\"• Item\")] })  // BAD\nnew Paragraph({ children: [new TextRun(\"\\u2022 Item\")] })  // BAD\n\n// ✅ CORRECT - use numbering config with LevelFormat.BULLET\nconst doc = new Document({\n  numbering: {\n    config: [\n      { reference: \"bullets\",\n        levels: [{ level: 0, format: LevelFormat.BULLET, text: \"•\", alignment: AlignmentType.LEFT,\n          style: { paragraph: { indent: { left: 720, hanging: 360 } } } }] },\n      { reference: \"numbers\",\n        levels: [{ level: 0, format: LevelFormat.DECIMAL, text: \"%1.\", alignment: AlignmentType.LEFT,\n          style: { paragraph: { indent: { left: 720, hanging: 360 } } } }] },\n    ]\n  },\n  sections: [{\n    children: [\n      new Paragraph({ numbering: { reference: \"bullets\", level: 0 },\n        children: [new TextRun(\"Bullet item\")] }),\n      new Paragraph({ numbering: { reference: \"numbers\", level: 0 },\n        children: [new TextRun(\"Numbered item\")] }),\n    ]\n  }]\n});\n\n// ⚠️ Each reference creates INDEPENDENT numbering\n// Same reference = continues (1,2,3 then 4,5,6)\n// Different reference = restarts (1,2,3 then 1,2,3)"
      },
      {
        "title": "Tables",
        "body": "CRITICAL: Tables need dual widths - set both columnWidths on the table AND width on each cell. Without both, tables render incorrectly on some platforms.\n\n// CRITICAL: Always set table width for consistent rendering\n// CRITICAL: Use ShadingType.CLEAR (not SOLID) to prevent black backgrounds\nconst border = { style: BorderStyle.SINGLE, size: 1, color: \"CCCCCC\" };\nconst borders = { top: border, bottom: border, left: border, right: border };\n\nnew Table({\n  width: { size: 9360, type: WidthType.DXA }, // Always use DXA (percentages break in Google Docs)\n  columnWidths: [4680, 4680], // Must sum to table width (DXA: 1440 = 1 inch)\n  rows: [\n    new TableRow({\n      children: [\n        new TableCell({\n          borders,\n          width: { size: 4680, type: WidthType.DXA }, // Also set on each cell\n          shading: { fill: \"D5E8F0\", type: ShadingType.CLEAR }, // CLEAR not SOLID\n          margins: { top: 80, bottom: 80, left: 120, right: 120 }, // Cell padding (internal, not added to width)\n          children: [new Paragraph({ children: [new TextRun(\"Cell\")] })]\n        })\n      ]\n    })\n  ]\n})\n\nTable width calculation:\n\nAlways use WidthType.DXA — WidthType.PERCENTAGE breaks in Google Docs.\n\n// Table width = sum of columnWidths = content width\n// US Letter with 1\" margins: 12240 - 2880 = 9360 DXA\nwidth: { size: 9360, type: WidthType.DXA },\ncolumnWidths: [7000, 2360]  // Must sum to table width\n\nWidth rules:\n\nAlways use WidthType.DXA — never WidthType.PERCENTAGE (incompatible with Google Docs)\nTable width must equal the sum of columnWidths\nCell width must match corresponding columnWidth\nCell margins are internal padding - they reduce content area, not add to cell width\nFor full-width tables: use content width (page width minus left and right margins)"
      },
      {
        "title": "Images",
        "body": "// CRITICAL: type parameter is REQUIRED\nnew Paragraph({\n  children: [new ImageRun({\n    type: \"png\", // Required: png, jpg, jpeg, gif, bmp, svg\n    data: fs.readFileSync(\"image.png\"),\n    transformation: { width: 200, height: 150 },\n    altText: { title: \"Title\", description: \"Desc\", name: \"Name\" } // All three required\n  })]\n})"
      },
      {
        "title": "Page Breaks",
        "body": "// CRITICAL: PageBreak must be inside a Paragraph\nnew Paragraph({ children: [new PageBreak()] })\n\n// Or use pageBreakBefore\nnew Paragraph({ pageBreakBefore: true, children: [new TextRun(\"New page\")] })"
      },
      {
        "title": "Table of Contents",
        "body": "// CRITICAL: Headings must use HeadingLevel ONLY - no custom styles\nnew TableOfContents(\"Table of Contents\", { hyperlink: true, headingStyleRange: \"1-3\" })"
      },
      {
        "title": "Headers/Footers",
        "body": "sections: [{\n  properties: {\n    page: { margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } } // 1440 = 1 inch\n  },\n  headers: {\n    default: new Header({ children: [new Paragraph({ children: [new TextRun(\"Header\")] })] })\n  },\n  footers: {\n    default: new Footer({ children: [new Paragraph({\n      children: [new TextRun(\"Page \"), new TextRun({ children: [PageNumber.CURRENT] })]\n    })] })\n  },\n  children: [/* content */]\n}]"
      },
      {
        "title": "Critical Rules for docx-js",
        "body": "Set page size explicitly - docx-js defaults to A4; use US Letter (12240 x 15840 DXA) for US documents\nLandscape: pass portrait dimensions - docx-js swaps width/height internally; pass short edge as width, long edge as height, and set orientation: PageOrientation.LANDSCAPE\nNever use \\n - use separate Paragraph elements\nNever use unicode bullets - use LevelFormat.BULLET with numbering config\nPageBreak must be in Paragraph - standalone creates invalid XML\nImageRun requires type - always specify png/jpg/etc\nAlways set table width with DXA - never use WidthType.PERCENTAGE (breaks in Google Docs)\nTables need dual widths - columnWidths array AND cell width, both must match\nTable width = sum of columnWidths - for DXA, ensure they add up exactly\nAlways add cell margins - use margins: { top: 80, bottom: 80, left: 120, right: 120 } for readable padding\nUse ShadingType.CLEAR - never SOLID for table shading\nTOC requires HeadingLevel only - no custom styles on heading paragraphs\nOverride built-in styles - use exact IDs: \"Heading1\", \"Heading2\", etc.\nInclude outlineLevel - required for TOC (0 for H1, 1 for H2, etc.)"
      },
      {
        "title": "Editing Existing Documents",
        "body": "Follow all 3 steps in order."
      },
      {
        "title": "Step 1: Unpack",
        "body": "python scripts/office/unpack.py document.docx unpacked/\n\nExtracts XML, pretty-prints, merges adjacent runs, and converts smart quotes to XML entities (&#x201C; etc.) so they survive editing. Use --merge-runs false to skip run merging."
      },
      {
        "title": "Step 2: Edit XML",
        "body": "Edit files in unpacked/word/. See XML Reference below for patterns.\n\nUse \"Claude\" as the author for tracked changes and comments, unless the user explicitly requests use of a different name.\n\nUse the Edit tool directly for string replacement. Do not write Python scripts. Scripts introduce unnecessary complexity. The Edit tool shows exactly what is being replaced.\n\nCRITICAL: Use smart quotes for new content. When adding text with apostrophes or quotes, use XML entities to produce smart quotes:\n\n<!-- Use these entities for professional typography -->\n<w:t>Here&#x2019;s a quote: &#x201C;Hello&#x201D;</w:t>\n\nEntityCharacter&#x2018;‘ (left single)&#x2019;’ (right single / apostrophe)&#x201C;“ (left double)&#x201D;” (right double)\n\nAdding comments: Use comment.py to handle boilerplate across multiple XML files (text must be pre-escaped XML):\n\npython scripts/comment.py unpacked/ 0 \"Comment text with &amp; and &#x2019;\"\npython scripts/comment.py unpacked/ 1 \"Reply text\" --parent 0  # reply to comment 0\npython scripts/comment.py unpacked/ 0 \"Text\" --author \"Custom Author\"  # custom author name\n\nThen add markers to document.xml (see Comments in XML Reference)."
      },
      {
        "title": "Step 3: Pack",
        "body": "python scripts/office/pack.py unpacked/ output.docx --original document.docx\n\nValidates with auto-repair, condenses XML, and creates DOCX. Use --validate false to skip.\n\nAuto-repair will fix:\n\ndurableId >= 0x7FFFFFFF (regenerates valid ID)\nMissing xml:space=\"preserve\" on <w:t> with whitespace\n\nAuto-repair won't fix:\n\nMalformed XML, invalid element nesting, missing relationships, schema violations"
      },
      {
        "title": "Common Pitfalls",
        "body": "Replace entire <w:r> elements: When adding tracked changes, replace the whole <w:r>...</w:r> block with <w:del>...<w:ins>... as siblings. Don't inject tracked change tags inside a run.\nPreserve <w:rPr> formatting: Copy the original run's <w:rPr> block into your tracked change runs to maintain bold, font size, etc."
      },
      {
        "title": "Schema Compliance",
        "body": "Element order in <w:pPr>: <w:pStyle>, <w:numPr>, <w:spacing>, <w:ind>, <w:jc>, <w:rPr> last\nWhitespace: Add xml:space=\"preserve\" to <w:t> with leading/trailing spaces\nRSIDs: Must be 8-digit hex (e.g., 00AB1234)"
      },
      {
        "title": "Tracked Changes",
        "body": "Insertion:\n\n<w:ins w:id=\"1\" w:author=\"Claude\" w:date=\"2025-01-01T00:00:00Z\">\n  <w:r><w:t>inserted text</w:t></w:r>\n</w:ins>\n\nDeletion:\n\n<w:del w:id=\"2\" w:author=\"Claude\" w:date=\"2025-01-01T00:00:00Z\">\n  <w:r><w:delText>deleted text</w:delText></w:r>\n</w:del>\n\nInside <w:del>: Use <w:delText> instead of <w:t>, and <w:delInstrText> instead of <w:instrText>.\n\nMinimal edits - only mark what changes:\n\n<!-- Change \"30 days\" to \"60 days\" -->\n<w:r><w:t>The term is </w:t></w:r>\n<w:del w:id=\"1\" w:author=\"Claude\" w:date=\"...\">\n  <w:r><w:delText>30</w:delText></w:r>\n</w:del>\n<w:ins w:id=\"2\" w:author=\"Claude\" w:date=\"...\">\n  <w:r><w:t>60</w:t></w:r>\n</w:ins>\n<w:r><w:t> days.</w:t></w:r>\n\nDeleting entire paragraphs/list items - when removing ALL content from a paragraph, also mark the paragraph mark as deleted so it merges with the next paragraph. Add <w:del/> inside <w:pPr><w:rPr>:\n\n<w:p>\n  <w:pPr>\n    <w:numPr>...</w:numPr>  <!-- list numbering if present -->\n    <w:rPr>\n      <w:del w:id=\"1\" w:author=\"Claude\" w:date=\"2025-01-01T00:00:00Z\"/>\n    </w:rPr>\n  </w:pPr>\n  <w:del w:id=\"2\" w:author=\"Claude\" w:date=\"2025-01-01T00:00:00Z\">\n    <w:r><w:delText>Entire paragraph content being deleted...</w:delText></w:r>\n  </w:del>\n</w:p>\n\nWithout the <w:del/> in <w:pPr><w:rPr>, accepting changes leaves an empty paragraph/list item.\n\nRejecting another author's insertion - nest deletion inside their insertion:\n\n<w:ins w:author=\"Jane\" w:id=\"5\">\n  <w:del w:author=\"Claude\" w:id=\"10\">\n    <w:r><w:delText>their inserted text</w:delText></w:r>\n  </w:del>\n</w:ins>\n\nRestoring another author's deletion - add insertion after (don't modify their deletion):\n\n<w:del w:author=\"Jane\" w:id=\"5\">\n  <w:r><w:delText>deleted text</w:delText></w:r>\n</w:del>\n<w:ins w:author=\"Claude\" w:id=\"10\">\n  <w:r><w:t>deleted text</w:t></w:r>\n</w:ins>"
      },
      {
        "title": "Comments",
        "body": "After running comment.py (see Step 2), add markers to document.xml. For replies, use --parent flag and nest markers inside the parent's.\n\nCRITICAL: <w:commentRangeStart> and <w:commentRangeEnd> are siblings of <w:r>, never inside <w:r>.\n\n<!-- Comment markers are direct children of w:p, never inside w:r -->\n<w:commentRangeStart w:id=\"0\"/>\n<w:del w:id=\"1\" w:author=\"Claude\" w:date=\"2025-01-01T00:00:00Z\">\n  <w:r><w:delText>deleted</w:delText></w:r>\n</w:del>\n<w:r><w:t> more text</w:t></w:r>\n<w:commentRangeEnd w:id=\"0\"/>\n<w:r><w:rPr><w:rStyle w:val=\"CommentReference\"/></w:rPr><w:commentReference w:id=\"0\"/></w:r>\n\n<!-- Comment 0 with reply 1 nested inside -->\n<w:commentRangeStart w:id=\"0\"/>\n  <w:commentRangeStart w:id=\"1\"/>\n  <w:r><w:t>text</w:t></w:r>\n  <w:commentRangeEnd w:id=\"1\"/>\n<w:commentRangeEnd w:id=\"0\"/>\n<w:r><w:rPr><w:rStyle w:val=\"CommentReference\"/></w:rPr><w:commentReference w:id=\"0\"/></w:r>\n<w:r><w:rPr><w:rStyle w:val=\"CommentReference\"/></w:rPr><w:commentReference w:id=\"1\"/></w:r>"
      },
      {
        "title": "Images",
        "body": "Add image file to word/media/\nAdd relationship to word/_rels/document.xml.rels:\n\n<Relationship Id=\"rId5\" Type=\".../image\" Target=\"media/image1.png\"/>\n\nAdd content type to [Content_Types].xml:\n\n<Default Extension=\"png\" ContentType=\"image/png\"/>\n\nReference in document.xml:\n\n<w:drawing>\n  <wp:inline>\n    <wp:extent cx=\"914400\" cy=\"914400\"/>  <!-- EMUs: 914400 = 1 inch -->\n    <a:graphic>\n      <a:graphicData uri=\".../picture\">\n        <pic:pic>\n          <pic:blipFill><a:blip r:embed=\"rId5\"/></pic:blipFill>\n        </pic:pic>\n      </a:graphicData>\n    </a:graphic>\n  </wp:inline>\n</w:drawing>"
      },
      {
        "title": "Dependencies",
        "body": "pandoc: Text extraction\ndocx: npm install -g docx (new documents)\nLibreOffice: PDF conversion (auto-configured for sandboxed environments via scripts/office/soffice.py)\nPoppler: pdftoppm for images"
      }
    ],
    "body": "DOCX creation, editing, and analysis\nOverview\n\nA .docx file is a ZIP archive containing XML files.\n\nQuick Reference\nTask\tApproach\nRead/analyze content\tpandoc or unpack for raw XML\nCreate new document\tUse docx-js - see Creating New Documents below\nEdit existing document\tUnpack → edit XML → repack - see Editing Existing Documents below\nConverting .doc to .docx\n\nLegacy .doc files must be converted before editing:\n\npython scripts/office/soffice.py --headless --convert-to docx document.doc\n\nReading Content\n# Text extraction with tracked changes\npandoc --track-changes=all document.docx -o output.md\n\n# Raw XML access\npython scripts/office/unpack.py document.docx unpacked/\n\nConverting to Images\npython scripts/office/soffice.py --headless --convert-to pdf document.docx\npdftoppm -jpeg -r 150 document.pdf page\n\nAccepting Tracked Changes\n\nTo produce a clean document with all tracked changes accepted (requires LibreOffice):\n\npython scripts/accept_changes.py input.docx output.docx\n\nCreating New Documents\n\nGenerate .docx files with JavaScript, then validate. Install: npm install -g docx\n\nSetup\nconst { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell, ImageRun,\n        Header, Footer, AlignmentType, PageOrientation, LevelFormat, ExternalHyperlink,\n        TableOfContents, HeadingLevel, BorderStyle, WidthType, ShadingType,\n        VerticalAlign, PageNumber, PageBreak } = require('docx');\n\nconst doc = new Document({ sections: [{ children: [/* content */] }] });\nPacker.toBuffer(doc).then(buffer => fs.writeFileSync(\"doc.docx\", buffer));\n\nValidation\n\nAfter creating the file, validate it. If validation fails, unpack, fix the XML, and repack.\n\npython scripts/office/validate.py doc.docx\n\nPage Size\n// CRITICAL: docx-js defaults to A4, not US Letter\n// Always set page size explicitly for consistent results\nsections: [{\n  properties: {\n    page: {\n      size: {\n        width: 12240,   // 8.5 inches in DXA\n        height: 15840   // 11 inches in DXA\n      },\n      margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } // 1 inch margins\n    }\n  },\n  children: [/* content */]\n}]\n\n\nCommon page sizes (DXA units, 1440 DXA = 1 inch):\n\nPaper\tWidth\tHeight\tContent Width (1\" margins)\nUS Letter\t12,240\t15,840\t9,360\nA4 (default)\t11,906\t16,838\t9,026\n\nLandscape orientation: docx-js swaps width/height internally, so pass portrait dimensions and let it handle the swap:\n\nsize: {\n  width: 12240,   // Pass SHORT edge as width\n  height: 15840,  // Pass LONG edge as height\n  orientation: PageOrientation.LANDSCAPE  // docx-js swaps them in the XML\n},\n// Content width = 15840 - left margin - right margin (uses the long edge)\n\nStyles (Override Built-in Headings)\n\nUse Arial as the default font (universally supported). Keep titles black for readability.\n\nconst doc = new Document({\n  styles: {\n    default: { document: { run: { font: \"Arial\", size: 24 } } }, // 12pt default\n    paragraphStyles: [\n      // IMPORTANT: Use exact IDs to override built-in styles\n      { id: \"Heading1\", name: \"Heading 1\", basedOn: \"Normal\", next: \"Normal\", quickFormat: true,\n        run: { size: 32, bold: true, font: \"Arial\" },\n        paragraph: { spacing: { before: 240, after: 240 }, outlineLevel: 0 } }, // outlineLevel required for TOC\n      { id: \"Heading2\", name: \"Heading 2\", basedOn: \"Normal\", next: \"Normal\", quickFormat: true,\n        run: { size: 28, bold: true, font: \"Arial\" },\n        paragraph: { spacing: { before: 180, after: 180 }, outlineLevel: 1 } },\n    ]\n  },\n  sections: [{\n    children: [\n      new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun(\"Title\")] }),\n    ]\n  }]\n});\n\nLists (NEVER use unicode bullets)\n// ❌ WRONG - never manually insert bullet characters\nnew Paragraph({ children: [new TextRun(\"• Item\")] })  // BAD\nnew Paragraph({ children: [new TextRun(\"\\u2022 Item\")] })  // BAD\n\n// ✅ CORRECT - use numbering config with LevelFormat.BULLET\nconst doc = new Document({\n  numbering: {\n    config: [\n      { reference: \"bullets\",\n        levels: [{ level: 0, format: LevelFormat.BULLET, text: \"•\", alignment: AlignmentType.LEFT,\n          style: { paragraph: { indent: { left: 720, hanging: 360 } } } }] },\n      { reference: \"numbers\",\n        levels: [{ level: 0, format: LevelFormat.DECIMAL, text: \"%1.\", alignment: AlignmentType.LEFT,\n          style: { paragraph: { indent: { left: 720, hanging: 360 } } } }] },\n    ]\n  },\n  sections: [{\n    children: [\n      new Paragraph({ numbering: { reference: \"bullets\", level: 0 },\n        children: [new TextRun(\"Bullet item\")] }),\n      new Paragraph({ numbering: { reference: \"numbers\", level: 0 },\n        children: [new TextRun(\"Numbered item\")] }),\n    ]\n  }]\n});\n\n// ⚠️ Each reference creates INDEPENDENT numbering\n// Same reference = continues (1,2,3 then 4,5,6)\n// Different reference = restarts (1,2,3 then 1,2,3)\n\nTables\n\nCRITICAL: Tables need dual widths - set both columnWidths on the table AND width on each cell. Without both, tables render incorrectly on some platforms.\n\n// CRITICAL: Always set table width for consistent rendering\n// CRITICAL: Use ShadingType.CLEAR (not SOLID) to prevent black backgrounds\nconst border = { style: BorderStyle.SINGLE, size: 1, color: \"CCCCCC\" };\nconst borders = { top: border, bottom: border, left: border, right: border };\n\nnew Table({\n  width: { size: 9360, type: WidthType.DXA }, // Always use DXA (percentages break in Google Docs)\n  columnWidths: [4680, 4680], // Must sum to table width (DXA: 1440 = 1 inch)\n  rows: [\n    new TableRow({\n      children: [\n        new TableCell({\n          borders,\n          width: { size: 4680, type: WidthType.DXA }, // Also set on each cell\n          shading: { fill: \"D5E8F0\", type: ShadingType.CLEAR }, // CLEAR not SOLID\n          margins: { top: 80, bottom: 80, left: 120, right: 120 }, // Cell padding (internal, not added to width)\n          children: [new Paragraph({ children: [new TextRun(\"Cell\")] })]\n        })\n      ]\n    })\n  ]\n})\n\n\nTable width calculation:\n\nAlways use WidthType.DXA — WidthType.PERCENTAGE breaks in Google Docs.\n\n// Table width = sum of columnWidths = content width\n// US Letter with 1\" margins: 12240 - 2880 = 9360 DXA\nwidth: { size: 9360, type: WidthType.DXA },\ncolumnWidths: [7000, 2360]  // Must sum to table width\n\n\nWidth rules:\n\nAlways use WidthType.DXA — never WidthType.PERCENTAGE (incompatible with Google Docs)\nTable width must equal the sum of columnWidths\nCell width must match corresponding columnWidth\nCell margins are internal padding - they reduce content area, not add to cell width\nFor full-width tables: use content width (page width minus left and right margins)\nImages\n// CRITICAL: type parameter is REQUIRED\nnew Paragraph({\n  children: [new ImageRun({\n    type: \"png\", // Required: png, jpg, jpeg, gif, bmp, svg\n    data: fs.readFileSync(\"image.png\"),\n    transformation: { width: 200, height: 150 },\n    altText: { title: \"Title\", description: \"Desc\", name: \"Name\" } // All three required\n  })]\n})\n\nPage Breaks\n// CRITICAL: PageBreak must be inside a Paragraph\nnew Paragraph({ children: [new PageBreak()] })\n\n// Or use pageBreakBefore\nnew Paragraph({ pageBreakBefore: true, children: [new TextRun(\"New page\")] })\n\nTable of Contents\n// CRITICAL: Headings must use HeadingLevel ONLY - no custom styles\nnew TableOfContents(\"Table of Contents\", { hyperlink: true, headingStyleRange: \"1-3\" })\n\nHeaders/Footers\nsections: [{\n  properties: {\n    page: { margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } } // 1440 = 1 inch\n  },\n  headers: {\n    default: new Header({ children: [new Paragraph({ children: [new TextRun(\"Header\")] })] })\n  },\n  footers: {\n    default: new Footer({ children: [new Paragraph({\n      children: [new TextRun(\"Page \"), new TextRun({ children: [PageNumber.CURRENT] })]\n    })] })\n  },\n  children: [/* content */]\n}]\n\nCritical Rules for docx-js\nSet page size explicitly - docx-js defaults to A4; use US Letter (12240 x 15840 DXA) for US documents\nLandscape: pass portrait dimensions - docx-js swaps width/height internally; pass short edge as width, long edge as height, and set orientation: PageOrientation.LANDSCAPE\nNever use \\n - use separate Paragraph elements\nNever use unicode bullets - use LevelFormat.BULLET with numbering config\nPageBreak must be in Paragraph - standalone creates invalid XML\nImageRun requires type - always specify png/jpg/etc\nAlways set table width with DXA - never use WidthType.PERCENTAGE (breaks in Google Docs)\nTables need dual widths - columnWidths array AND cell width, both must match\nTable width = sum of columnWidths - for DXA, ensure they add up exactly\nAlways add cell margins - use margins: { top: 80, bottom: 80, left: 120, right: 120 } for readable padding\nUse ShadingType.CLEAR - never SOLID for table shading\nTOC requires HeadingLevel only - no custom styles on heading paragraphs\nOverride built-in styles - use exact IDs: \"Heading1\", \"Heading2\", etc.\nInclude outlineLevel - required for TOC (0 for H1, 1 for H2, etc.)\nEditing Existing Documents\n\nFollow all 3 steps in order.\n\nStep 1: Unpack\npython scripts/office/unpack.py document.docx unpacked/\n\n\nExtracts XML, pretty-prints, merges adjacent runs, and converts smart quotes to XML entities (&#x201C; etc.) so they survive editing. Use --merge-runs false to skip run merging.\n\nStep 2: Edit XML\n\nEdit files in unpacked/word/. See XML Reference below for patterns.\n\nUse \"Claude\" as the author for tracked changes and comments, unless the user explicitly requests use of a different name.\n\nUse the Edit tool directly for string replacement. Do not write Python scripts. Scripts introduce unnecessary complexity. The Edit tool shows exactly what is being replaced.\n\nCRITICAL: Use smart quotes for new content. When adding text with apostrophes or quotes, use XML entities to produce smart quotes:\n\n<!-- Use these entities for professional typography -->\n<w:t>Here&#x2019;s a quote: &#x201C;Hello&#x201D;</w:t>\n\nEntity\tCharacter\n&#x2018;\t‘ (left single)\n&#x2019;\t’ (right single / apostrophe)\n&#x201C;\t“ (left double)\n&#x201D;\t” (right double)\n\nAdding comments: Use comment.py to handle boilerplate across multiple XML files (text must be pre-escaped XML):\n\npython scripts/comment.py unpacked/ 0 \"Comment text with &amp; and &#x2019;\"\npython scripts/comment.py unpacked/ 1 \"Reply text\" --parent 0  # reply to comment 0\npython scripts/comment.py unpacked/ 0 \"Text\" --author \"Custom Author\"  # custom author name\n\n\nThen add markers to document.xml (see Comments in XML Reference).\n\nStep 3: Pack\npython scripts/office/pack.py unpacked/ output.docx --original document.docx\n\n\nValidates with auto-repair, condenses XML, and creates DOCX. Use --validate false to skip.\n\nAuto-repair will fix:\n\ndurableId >= 0x7FFFFFFF (regenerates valid ID)\nMissing xml:space=\"preserve\" on <w:t> with whitespace\n\nAuto-repair won't fix:\n\nMalformed XML, invalid element nesting, missing relationships, schema violations\nCommon Pitfalls\nReplace entire <w:r> elements: When adding tracked changes, replace the whole <w:r>...</w:r> block with <w:del>...<w:ins>... as siblings. Don't inject tracked change tags inside a run.\nPreserve <w:rPr> formatting: Copy the original run's <w:rPr> block into your tracked change runs to maintain bold, font size, etc.\nXML Reference\nSchema Compliance\nElement order in <w:pPr>: <w:pStyle>, <w:numPr>, <w:spacing>, <w:ind>, <w:jc>, <w:rPr> last\nWhitespace: Add xml:space=\"preserve\" to <w:t> with leading/trailing spaces\nRSIDs: Must be 8-digit hex (e.g., 00AB1234)\nTracked Changes\n\nInsertion:\n\n<w:ins w:id=\"1\" w:author=\"Claude\" w:date=\"2025-01-01T00:00:00Z\">\n  <w:r><w:t>inserted text</w:t></w:r>\n</w:ins>\n\n\nDeletion:\n\n<w:del w:id=\"2\" w:author=\"Claude\" w:date=\"2025-01-01T00:00:00Z\">\n  <w:r><w:delText>deleted text</w:delText></w:r>\n</w:del>\n\n\nInside <w:del>: Use <w:delText> instead of <w:t>, and <w:delInstrText> instead of <w:instrText>.\n\nMinimal edits - only mark what changes:\n\n<!-- Change \"30 days\" to \"60 days\" -->\n<w:r><w:t>The term is </w:t></w:r>\n<w:del w:id=\"1\" w:author=\"Claude\" w:date=\"...\">\n  <w:r><w:delText>30</w:delText></w:r>\n</w:del>\n<w:ins w:id=\"2\" w:author=\"Claude\" w:date=\"...\">\n  <w:r><w:t>60</w:t></w:r>\n</w:ins>\n<w:r><w:t> days.</w:t></w:r>\n\n\nDeleting entire paragraphs/list items - when removing ALL content from a paragraph, also mark the paragraph mark as deleted so it merges with the next paragraph. Add <w:del/> inside <w:pPr><w:rPr>:\n\n<w:p>\n  <w:pPr>\n    <w:numPr>...</w:numPr>  <!-- list numbering if present -->\n    <w:rPr>\n      <w:del w:id=\"1\" w:author=\"Claude\" w:date=\"2025-01-01T00:00:00Z\"/>\n    </w:rPr>\n  </w:pPr>\n  <w:del w:id=\"2\" w:author=\"Claude\" w:date=\"2025-01-01T00:00:00Z\">\n    <w:r><w:delText>Entire paragraph content being deleted...</w:delText></w:r>\n  </w:del>\n</w:p>\n\n\nWithout the <w:del/> in <w:pPr><w:rPr>, accepting changes leaves an empty paragraph/list item.\n\nRejecting another author's insertion - nest deletion inside their insertion:\n\n<w:ins w:author=\"Jane\" w:id=\"5\">\n  <w:del w:author=\"Claude\" w:id=\"10\">\n    <w:r><w:delText>their inserted text</w:delText></w:r>\n  </w:del>\n</w:ins>\n\n\nRestoring another author's deletion - add insertion after (don't modify their deletion):\n\n<w:del w:author=\"Jane\" w:id=\"5\">\n  <w:r><w:delText>deleted text</w:delText></w:r>\n</w:del>\n<w:ins w:author=\"Claude\" w:id=\"10\">\n  <w:r><w:t>deleted text</w:t></w:r>\n</w:ins>\n\nComments\n\nAfter running comment.py (see Step 2), add markers to document.xml. For replies, use --parent flag and nest markers inside the parent's.\n\nCRITICAL: <w:commentRangeStart> and <w:commentRangeEnd> are siblings of <w:r>, never inside <w:r>.\n\n<!-- Comment markers are direct children of w:p, never inside w:r -->\n<w:commentRangeStart w:id=\"0\"/>\n<w:del w:id=\"1\" w:author=\"Claude\" w:date=\"2025-01-01T00:00:00Z\">\n  <w:r><w:delText>deleted</w:delText></w:r>\n</w:del>\n<w:r><w:t> more text</w:t></w:r>\n<w:commentRangeEnd w:id=\"0\"/>\n<w:r><w:rPr><w:rStyle w:val=\"CommentReference\"/></w:rPr><w:commentReference w:id=\"0\"/></w:r>\n\n<!-- Comment 0 with reply 1 nested inside -->\n<w:commentRangeStart w:id=\"0\"/>\n  <w:commentRangeStart w:id=\"1\"/>\n  <w:r><w:t>text</w:t></w:r>\n  <w:commentRangeEnd w:id=\"1\"/>\n<w:commentRangeEnd w:id=\"0\"/>\n<w:r><w:rPr><w:rStyle w:val=\"CommentReference\"/></w:rPr><w:commentReference w:id=\"0\"/></w:r>\n<w:r><w:rPr><w:rStyle w:val=\"CommentReference\"/></w:rPr><w:commentReference w:id=\"1\"/></w:r>\n\nImages\nAdd image file to word/media/\nAdd relationship to word/_rels/document.xml.rels:\n<Relationship Id=\"rId5\" Type=\".../image\" Target=\"media/image1.png\"/>\n\nAdd content type to [Content_Types].xml:\n<Default Extension=\"png\" ContentType=\"image/png\"/>\n\nReference in document.xml:\n<w:drawing>\n  <wp:inline>\n    <wp:extent cx=\"914400\" cy=\"914400\"/>  <!-- EMUs: 914400 = 1 inch -->\n    <a:graphic>\n      <a:graphicData uri=\".../picture\">\n        <pic:pic>\n          <pic:blipFill><a:blip r:embed=\"rId5\"/></pic:blipFill>\n        </pic:pic>\n      </a:graphicData>\n    </a:graphic>\n  </wp:inline>\n</w:drawing>\n\nDependencies\npandoc: Text extraction\ndocx: npm install -g docx (new documents)\nLibreOffice: PDF conversion (auto-configured for sandboxed environments via scripts/office/soffice.py)\nPoppler: pdftoppm for images"
  },
  "trust": {
    "sourceLabel": "tencent",
    "provenanceUrl": "https://clawhub.ai/guohongbin-git/docx-cn",
    "publisherUrl": "https://clawhub.ai/guohongbin-git/docx-cn",
    "owner": "guohongbin-git",
    "version": "1.0.1",
    "license": null,
    "verificationStatus": "Indexed source record"
  },
  "links": {
    "detailUrl": "https://openagent3.xyz/skills/docx-cn",
    "downloadUrl": "https://openagent3.xyz/downloads/docx-cn",
    "agentUrl": "https://openagent3.xyz/skills/docx-cn/agent",
    "manifestUrl": "https://openagent3.xyz/skills/docx-cn/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/docx-cn/agent.md"
  }
}