← Tines 3BCONTENT HISTORY

Update to Tines 3B

Snapshot Nov 17, 2026 · 12:11 UTC · version 1.0.3

Collection source: downloaded plugin package.

WHAT CHANGED

First saved snapshot

No earlier snapshot is available to establish a change.

Save Tines 3B and check future changes in Following.

Up to 3 plugins free · no card required.

Compare saved observations

Download comparison JSON
Full technical diff · 0 changed fields
Full snapshot data
{
  "description": "Create, edit, and read Word documents (.docx) with python-docx. Use whenever the user wants a Word file as output — a report, memo, letter, contract, proposal, or template fill — or uploads a .docx to summarize, review, comment on, redline, or rewrite, even if they only say “document” or “Word”.",
  "included_files": [
    {
      "relative_path": "references/tracked-changes.md",
      "size_in_bytes": 2643
    }
  ],
  "name": "docx",
  "skill_md_contents": "---\nname: docx\ndescription: Create, edit, and read Word documents (.docx) with python-docx. Use whenever the user wants a Word file as output — a report, memo, letter, contract, proposal, or template fill — or uploads a .docx to summarize, review, comment on, redline, or rewrite, even if they only say “document” or “Word”.\nlicense: Apache-2.0\ncompatibility: Tines 3B\n---\n\n# Word documents\n\nWork with `.docx` files in Python through `execute`, adding `python-docx==1.2.0` to a `requirements.txt` in `files`. In a workflow step, add it to the step’s `requirements.txt` instead.\n\nUser uploads arrive under `/3b/uploads/<id>/<file>`, which every execution can read. Write output to a persistent volume, such as `volumes: [\"documents\"]` and `/storage/documents/report.docx`, then call `showStorageFile` so the user can preview and download it. Never overwrite the user’s upload: save edits as a new file, and call `showStorageFile` again after each change.\n\n## Reading\n\nWalk the body in order so paragraphs and tables stay interleaved as the author wrote them:\n\n```python\nfrom docx import Document\nfrom docx.table import Table\nfrom docx.text.paragraph import Paragraph\n\ndoc = Document(\"/3b/uploads/abc/contract.docx\")\nfor block in doc.iter_inner_content():\n    if isinstance(block, Paragraph) and block.text.strip():\n        print(f\"[{block.style.name}] {block.text}\")\n    elif isinstance(block, Table):\n        for row in block.rows:\n            print(\" | \".join(cell.text for cell in row.cells))\n```\n\npython-docx skips text inside tracked insertions (`w:ins`), text boxes, and footnotes. If the document has redlines or the output looks incomplete, read `word/document.xml` from the zip as well.\n\n## Creating\n\nStructure first, styling second. Use the built-in styles rather than hand-formatting each paragraph: Word builds its navigation pane and table of contents from real headings, and a restyle then changes the whole document at once.\n\n```python\nfrom docx import Document\nfrom docx.enum.text import WD_ALIGN_PARAGRAPH\nfrom docx.oxml import OxmlElement\nfrom docx.oxml.ns import qn\nfrom docx.shared import Inches, Pt\n\ndoc = Document()\nsection = doc.sections[0]\nsection.page_width, section.page_height = Inches(8.5), Inches(11)\nfor side in (\"left_margin\", \"right_margin\", \"top_margin\", \"bottom_margin\"):\n    setattr(section, side, Inches(1))\n\nnormal = doc.styles[\"Normal\"]\nnormal.font.name = \"Calibri\"\nnormal.font.size = Pt(11)\n\ndoc.add_heading(\"Quarterly access review\", level=0)\ndoc.add_paragraph(\"Summary of findings for Q3.\")\ndoc.add_heading(\"Findings\", level=1)\ndoc.add_paragraph(\"Three dormant admin accounts\", style=\"List Bullet\")\ndoc.add_paragraph(\"Disable dormant accounts\", style=\"List Number\")\n\ntable = doc.add_table(rows=1, cols=3, style=\"Light Grid Accent 1\")\nfor cell, label in zip(table.rows[0].cells, (\"System\", \"Owner\", \"Status\")):\n    cell.text = label\nfor values in ((\"Okta\", \"IT\", \"Done\"), (\"AWS\", \"Platform\", \"Open\")):\n    for cell, value in zip(table.add_row().cells, values):\n        cell.text = value\n\nfooter = section.footer.paragraphs[0]\nfooter.alignment = WD_ALIGN_PARAGRAPH.CENTER\nfor kind, text in ((\"begin\", None), (None, \"PAGE\"), (\"end\", None)):\n    run = footer.add_run()\n    if kind:\n        field = OxmlElement(\"w:fldChar\")\n        field.set(qn(\"w:fldCharType\"), kind)\n    else:\n        field = OxmlElement(\"w:instrText\")\n        field.text = text\n    run._r.append(field)\n\ndoc.save(\"/storage/documents/access-review.docx\")\n```\n\n- `Document()` defaults to US Letter. Use A4 (`Mm(210)` × `Mm(297)`) when the user or their organization is outside North America.\n- Add images with `doc.add_picture(path, width=Inches(6))`. Render charts to PNG with matplotlib first, at 200 DPI or more.\n- Start a new page with `doc.add_page_break()`, not a run of empty paragraphs.\n- Python-docx has no table-of-contents builder. Insert a `TOC \\o \"1-3\" \\h` field the same way as the page number above, and tell the user to update fields in Word to fill it.\n- Keep tables to five or six columns in portrait. Switch the section to landscape (`section.orientation`, then swap width and height) for wider tables.\n\n## Editing an existing document\n\nLoad the user’s file and change it in place, so their styles, numbering, headers, and section settings survive. Rebuilding a similar document from scratch loses formatting the user cares about.\n\nWord splits text into runs wherever formatting, spell-check, or revision history changes, so one sentence can span several runs. To replace text, edit only the runs the match overlaps: the replacement takes the formatting of the run where the match starts, and every other run keeps its own. Setting `paragraph.text` collapses every run into one and drops bold, italics, and links.\n\n```python\ndef replace_in_runs(runs, old, new):\n    \"\"\"Replace the first match of `old` across `runs`, touching only the runs it overlaps.\"\"\"\n    start = \"\".join(run.text for run in runs).find(old)\n    if start == -1:\n        return False\n    end = start + len(old)\n    position = 0\n    for run in runs:\n        run_start, text = position, run.text\n        position += len(text)\n        if position <= start or run_start >= end:\n            continue\n        after = text[end - run_start:] if position > end else \"\"\n        run.text = text[:start - run_start] + new + after if run_start <= start else after\n    return True\n\nreplace_in_runs(paragraph.runs, \"Acme Ltd\", \"Globex Corp\")\nfor link in paragraph.hyperlinks:\n    replace_in_runs(link.runs, \"Acme Ltd\", \"Globex Corp\")\n```\n\n`paragraph.runs` excludes text inside hyperlinks, which `paragraph.text` includes, so handle each hyperlink’s runs separately as above. The helper replaces one match per call, so call it again until it returns `False`, unless the replacement contains the search text. Search table cells, headers, and footers as well as `doc.paragraphs`. For a template with placeholders like `{{client_name}}`, check that no placeholder remains after filling it.\n\n## Comments and redlines\n\nTo review a document, attach comments rather than rewriting text:\n\n```python\nparagraph = doc.paragraphs[4]\ndoc.add_comment(paragraph.runs, text=\"Should this be 30 days?\", author=\"3B\", initials=\"3B\")\n```\n\nWhen the user asks for tracked changes, read [references/tracked-changes.md](references/tracked-changes.md): python-docx can’t write them, so they need direct XML edits.\n\n## Check the result\n\nReopen the saved file and print its headings, table count, and the first lines of each section to confirm it says what you intended. Then call `showStorageFile` so the user can see the rendered layout. Tell them what you produced and anything the preview can’t show, such as fields that update only when the file opens in Word.\n"
}

SHA-256 of public snapshot: de22afaf38b3e68018b43c4e4fea2fdc52e7c8163bc68e68f3a3aff9b18cb68c