Langsung ke konten
Skillpedia
PDF, Word & slide54k ยท #3368

docx

Fungsinya

Skill ini memungkinkan agent AI bekerja dengan dokumen Microsoft Word. Skill ini untuk orang yang membutuhkan laporan, surat, atau memo yang ditulis sebagai file Word, atau file Word yang sudah ada untuk dibaca dan diedit.

Kapan dipakai

  • โœ“Saat Anda membutuhkan laporan, surat, atau memo Word yang dibuat sebagai file .docx.
  • โœ“Saat Anda ingin teks atau tabel diambil dari file Word yang sudah ada.
  • โœ“Saat Anda membutuhkan perubahan terlacak atau komentar ditambahkan ke dokumen Word.

Link skill

https://github.com/HKUDS/DeepTutor/blob/main/deeptutor/skills/builtin/docx/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/HKUDS/DeepTutor/blob/main/deeptutor/skills/builtin/docx/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit โ†’

Contoh permintaan ke AI

โ€œUbah catatan ini menjadi laporan Word dengan judul bagian, tabel, dan nomor halaman.โ€

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Agent memakai pustaka python-docx untuk sebagian besar tugas, dan menulis XML Word mentah untuk kasus lanjutan seperti perubahan terlacak dan komentar. Agent menyimpan file output baru, bukan menimpa file asli.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

DOCX (Microsoft Word)

A .docx is a ZIP of XML parts. Body text lives in word/document.xml. Two tiers:

  • Default โ€” python-docx (preinstalled): create, read, and simple edits. Use for almost everything.
  • Advanced โ€” raw OOXML via zipfile: only for what python-docx cannot express โ€” tracked changes (redlines), comments, and exact-fidelity edits that must preserve every untouched byte. See Raw OOXML.

Runtime

Use exec with complete Python source (language: python). python-docx is preinstalled. Prefer creating, saving, reopening, and validating the deliverable in one call; later calls can revise the same relative filename. Follow the turn's User workspace instructions for locating inputs, output boundaries, and presenting the finished file. When editing, write a new output unless the user explicitly requested an authorized replacement.

Read / extract

from docx import Document

doc = Document("in.docx")
text = "\n".join(p.text for p in doc.paragraphs)  # body paragraphs
for tbl in doc.tables:  # tables
    for row in tbl.rows:
        print([c.text for c in row.cells])

doc.paragraphs skips text inside tables, headers/footers, and text boxes โ€” iterate doc.tables and doc.sections[i].header/.footer for those. Each paragraph's style: p.style.name (e.g. "Heading 1").

To read tracked changes, parse the XML directly โ€” python-docx ignores <w:ins>/<w:del>:

import zipfile, re

xml = zipfile.ZipFile("in.docx").read("word/document.xml").decode("utf-8")
# inserted text = <w:ins>โ€ฆ<w:t>โ€ฆ  deleted = <w:del>โ€ฆ<w:delText>โ€ฆ
print(re.findall(r"<w:t[^>]*>(.*?)</w:t>", xml))

Create

from docx import Document
from docx.shared import Pt, Inches, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH

doc = Document()  # default template page size
doc.add_heading("Quarterly Report", level=0)  # 0 = title; 1..9 = H1..H9
p = doc.add_paragraph("Intro paragraph. ")
run = p.add_run("Bold tail.")
run.bold = True
doc.add_paragraph("First item", style="List Bullet")  # real list style, never a "โ€ข " literal
doc.add_paragraph("Step one", style="List Number")

# Table โ€” header row + data
tbl = doc.add_table(rows=1, cols=2)
tbl.style = "Light Grid Accent 1"
tbl.rows[0].cells[0].text, tbl.rows[0].cells[1].text = "Metric", "Value"
for k, v in [("Revenue", "1.2M"), ("Growth", "15%")]:
    c = tbl.add_row().cells
    c[0].text, c[1].text = k, v

doc.add_picture("chart.png", width=Inches(5))  # image, scaled to width
doc.add_page_break()
doc.save("out.docx")

# Validate immediately; later exec calls can also reopen this relative path.
check = Document("out.docx")
assert check.paragraphs, "generated DOCX has no paragraphs"
import zipfile

with zipfile.ZipFile("out.docx") as package:
    assert package.testzip() is None, "generated DOCX has a corrupt ZIP member"

Rules:

  • Never type bullet/number characters (โ€ข, 1.) into text โ€” use style="List Bullet"/"List Number". Only list styles defined in the doc's template are available.
  • No \n inside a run โ€” each visual line is its own add_paragraph.
  • Built-in style names must match the template (e.g. "Heading 1", "List Bullet"); a wrong name raises KeyError.
  • Units: Pt, Inches, Cm from docx.shared. Colors: RGBColor(0x1F,0x4E,0x79).

Page setup, headers/footers, page numbers

from docx.shared import Inches

sec = doc.sections[0]
sec.page_width, sec.page_height = Inches(8.5), Inches(11)  # Letter
sec.top_margin = sec.bottom_margin = Inches(1)
sec.header.paragraphs[0].text = "Confidential"

Page-number fields aren't in the python-docx API; inject the field XML into a footer run:

from docx.oxml.ns import qn
from docx.oxml import OxmlElement


def add_page_number(paragraph):
    for t in ("begin", "instr", "end"):
        r = OxmlElement("w:r")
        if t == "instr":
            fld = OxmlElement("w:instrText")
            fld.set(qn("xml:space"), "preserve")
            fld.text = "PAGE"
        else:
            fld = OxmlElement("w:fldChar")
            fld.set(qn("w:fldCharType"), t)
        r.append(fld)
        paragraph._p.append(r)


add_page_number(doc.sections[0].footer.paragraphs[0])

A clickable Table of Contents is also a field; Word shows "right-click โ†’ Update Field" until refreshed. Same pattern with instrText = TOC \o "1-3" \h \z \u.

Edit existing (simple)

python-docx preserves the rest of the doc

Pertanyaan umum

Apakah skill ini bisa dipakai untuk file PDF atau Excel?

Tidak. Skill ini untuk file Word, dan menyatakan PDF, Excel, PowerPoint, dan Google Docs berada di luar lingkupnya.

Bisakah skill ini menambahkan daftar isi?

Bisa. Skill ini mencakup daftar isi dan nomor halaman.

Bisakah skill ini membuat perubahan terlacak?

Bisa. Skill ini dapat menerapkan perubahan terlacak dan komentar melalui metode lanjutannya.

Detail

Deskripsi asli dari pembuat

Read, create, or edit Microsoft Word .docx files โ€” extract/summarize text and tables, generate reports/letters/memos with headings, tables, images, TOC and page numbers, do find-and-replace, or apply tracked changes (redlines) and comments. Use whenever the user has a .docx or wants a Word deliverable. Not for PDF, .xlsx, .pptx, or Google Docs.

repo: HKUDS/DeepTutor

Popularitas

Bintang GitHub
54k
Peringkat
#3368
Lisensi
Apache-2.0
Diperbarui
31/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • โ€ฆ

Skill lain dari repositori ini

Skill serupa