SuperAPI AI Directory

hwp-fill

General & other

View repository

Updated 10-15 23:23

About this skill

Fill Hangul file

Input

$ARGUMENTS

Processing method by OS

Windows: use pyhwpx (recommended)

On Windows with the Hangul program installed, use pyhwpx.

from pyhwpx import Hwp

hwp = Hwp()
hwp.open("서식.hwp")  # .hwp, .hwpx 모두 지원
Fill values into fields

hwp.put_field_text("Research Project Name", "AI-based Diagnostic System") hwp.put_field_text("Principal Investigator", "Hong Gildong")

Save

hwp.save_as("result.hwp") hwp.quit()


**pyhwpx 설치**: `pip install pyhwpx`

**참고**: pyhwpx는 한글 문서의 "누름틀" 필드를 사용합니다. 서식에 누름틀이 없으면 표 셀을 직접 찾아서 수정해야 합니다.

### macOS/Linux: XML 직접 수정 (.hwpx만 지원)

#### 처리 절차

##### 1. HWPX 압축 해제

```bash
mkdir -p {임시디렉토리}
unzip -o {서식}.hwpx -d {임시디렉토리}/
2. Analyze the form file

{임시디렉토리}/Contents/section0.xml Read the file and:

  • 표(<hp:tbl>) search
  • Extract the field name from the first cell of each row
  • If the second cell is empty, it is an item to fill in
3. Identify the content

Extract field-value pairs from the MD file or user-provided content:

# 연구과제명
AI 기반 진단 시스템

## 연구책임자
홍길동

→ {"연구과제명": "AI 기반 진단 시스템", "연구책임자": "홍길동"}

4. Smart matching

Even if the field names do not match exactly, match flexibly:

  • 과제명 → 연구과제명 (partial match)
  • 책임자 → 연구책임자 (synonym)
  • 연구 기간 → 연구기간 (ignore spacing)

If ambiguous, always confirm with the user:

  • When there are multiple candidates
  • When the meaning may differ
  • When no field to match is found
5. Check the matching results

Show the matching results to the user and get confirmation:

매칭 결과:
- 연구과제명 ← "AI 기반 진단 시스템"
- 연구책임자 ← "홍길동"
- 연구기간 ← (내용 없음)

진행하시겠습니까?
6. Edit the XML

Use the Edit tool to section0.xmlmodify the contents of the corresponding cell in

Before modification:

<hp:tc><hp:p><hp:t></hp:t></hp:p></hp:tc>

After modification:

<hp:tc><hp:p><hp:t>홍길동</hp:t></hp:p></hp:tc>

Note: empty <hp:t> tag or <hp:t/> to enter the value.

7. Recompress
cd {임시디렉토리}
zip -r {출력파일}.hwpx *

Important: When compressing, you must run it inside a temporary directory.

8. Clean up
rm -rf {임시디렉토리}

Output

  • Default filename: {원본}_filled.hwpx (or .hwp)
  • If the user specifies an output filename, use that name
  • Report filled fields and unfilled fields

Precautions

  • On macOS/Linux, .hwpis not supported → guide the user to save again in Hangul as .hwpxguide to save again as
  • On Windows, pyhwpx supports both .hwp, .hwpx all supported
  • XML special character escaping: & → &amp;, < → &lt;, > → &gt;
  • If a line break is needed, use multiple <hp:p> tags
  • Do not modify the original file (create a new file)