Quickstart tour

The seven moves every hwpapi script uses

Sample output โ€” generated by tests/generate_v2_doc_artifacts.py running real HWP

Run the shortest useful script: open/new, insert text, format, find, save. Ported from examples/quickstart.py to the v2 surface.

from hwpapi import App
from hwpapi.context import charshape_scope
from hwpapi import units as U


def main():
    with App(is_visible=True) as app:
        app.new()

        # 1. Insert text
        app.doc.insert_text("hwpapi ํ…Œ์ŠคํŠธ ๋ฌธ์„œ\n\n")
        app.doc.insert_text("์ด ๋ฌธ์„œ๋Š” hwpapi๋กœ ์ž๋™ ์ƒ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.\n")

        # 2. Format: jump to top, select first line, apply heading style
        app.doc.cursor.goto_page(1)
        app.doc.select_text(0, len("hwpapi ํ…Œ์ŠคํŠธ ๋ฌธ์„œ"))

        with charshape_scope(app, bold=True, size=U.pt(18)):
            app.doc.insert_text("hwpapi ํ…Œ์ŠคํŠธ ๋ฌธ์„œ")

        # 3. Navigate and insert more
        app.doc.cursor.goto_end()
        app.doc.insert_text("\n")
        for i in range(3):
            app.doc.insert_text(f"โ€ข ํ•ญ๋ชฉ {i + 1}\n")

        # 4. Find / Replace
        count = app.doc.replace_all("ํ•ญ๋ชฉ", "list item")
        print(f"Replaced {count} occurrences")

        # 5. Action introspection (no COM calls beyond a listing)
        actions = app.actions
        print(f"\nAvailable actions: {len(actions.list_actions())}")

        # 6. Raw COM access (escape hatch)
        print(f"\nRaw HWP COM: {app.api.CLSID}")

        # 7. Save
        app.save_as("quickstart-output.hwp")


if __name__ == "__main__":
    main()

What changed from v1

v1 v2
app.insert_text(...) app.doc.insert_text(...)
app.move.top_of_file() app.doc.cursor.goto_page(1)
app.select_text() app.doc.select_text(...)
app.set_charshape(bold=True, height=1800) charshape_scope(app, bold=True, size=U.pt(18))
app.replace_all(...) app.doc.replace_all(...)
app.api.CLSID app.api.CLSID (unchanged โ€” api is still on App)
Back to top