python-hwpx 2.0__py3-none-any.whl → 2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hwpx/document.py CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import xml.etree.ElementTree as ET
5
6
  import io
6
7
  import warnings
7
8
  from datetime import datetime
@@ -0,0 +1,257 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-hwpx
3
+ Version: 2.1
4
+ Summary: Hancom HWPX 패키지를 로드하고 편집하기 위한 Python 유틸리티 모음
5
+ Author: python-hwpx Maintainers
6
+ License: Non-Commercial License
7
+
8
+ Copyright (c) 2024 python-hwpx Maintainers
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to use,
12
+ copy, modify, merge, publish, distribute, and sublicense the Software only for
13
+ non-commercial purposes, subject to the following conditions:
14
+
15
+ 1. Non-Commercial Use Only. The Software may be used, copied, modified,
16
+ merged, published, distributed, and sublicensed only for non-commercial
17
+ purposes. "Non-Commercial" means use that is not primarily intended for or
18
+ directed toward commercial advantage, monetary compensation, or any form of
19
+ direct or indirect commercial exploitation.
20
+
21
+ 2. Attribution. The above copyright notice and this permission notice shall be
22
+ included in all copies or substantial portions of the Software.
23
+
24
+ 3. No Warranty of Commercial Support. The maintainers are not obligated to
25
+ provide commercial support, maintenance, or updates.
26
+
27
+ THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL THE
30
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ SOFTWARE.
34
+
35
+ If you require permissions to use this Software for commercial purposes,
36
+ please contact the copyright holders to negotiate an alternative licensing
37
+ arrangement.
38
+
39
+ Project-URL: Homepage, https://github.com/airmang/python-hwpx
40
+ Project-URL: Documentation, https://github.com/airmang/python-hwpx/tree/main/docs
41
+ Project-URL: Issues, https://github.com/airmang/python-hwpx/issues
42
+ Keywords: hwp,hwpx,hancom,opc,xml
43
+ Classifier: Development Status :: 3 - Alpha
44
+ Classifier: Intended Audience :: Developers
45
+ Classifier: License :: OSI Approved :: MIT License
46
+ Classifier: Programming Language :: Python :: 3
47
+ Classifier: Programming Language :: Python :: 3.10
48
+ Classifier: Programming Language :: Python :: 3.11
49
+ Classifier: Programming Language :: Python :: 3.12
50
+ Classifier: Topic :: Software Development :: Libraries
51
+ Classifier: Topic :: Text Processing :: Markup :: XML
52
+ Requires-Python: >=3.10
53
+ Description-Content-Type: text/markdown
54
+ License-File: LICENSE
55
+ Requires-Dist: lxml<6,>=4.9
56
+ Provides-Extra: dev
57
+ Requires-Dist: build>=1.0; extra == "dev"
58
+ Requires-Dist: twine>=4.0; extra == "dev"
59
+ Requires-Dist: pytest>=7.4; extra == "dev"
60
+ Provides-Extra: test
61
+ Requires-Dist: pytest>=7.4; extra == "test"
62
+ Requires-Dist: pytest-cov>=5.0; extra == "test"
63
+ Provides-Extra: typecheck
64
+ Requires-Dist: mypy>=1.10; extra == "typecheck"
65
+ Requires-Dist: pyright>=1.1.390; extra == "typecheck"
66
+ Dynamic: license-file
67
+
68
+ <p align="center">
69
+ <h1 align="center">python-hwpx</h1>
70
+ <p align="center">
71
+ <strong>HWPX 문서를 Python으로 읽고, 편집하고, 생성합니다.</strong>
72
+ </p>
73
+ <p align="center">
74
+ <a href="https://pypi.org/project/python-hwpx/"><img src="https://img.shields.io/pypi/v/python-hwpx?color=blue&label=PyPI" alt="PyPI"></a>
75
+ <a href="https://pypi.org/project/python-hwpx/"><img src="https://img.shields.io/pypi/pyversions/python-hwpx" alt="Python"></a>
76
+ <a href="https://github.com/airmang/python-hwpx/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Non--Commercial-green" alt="License"></a>
77
+ <a href="https://airmang.github.io/python-hwpx/"><img src="https://img.shields.io/badge/docs-Sphinx-8CA1AF" alt="Docs"></a>
78
+ </p>
79
+ </p>
80
+
81
+ ---
82
+
83
+ `python-hwpx`는 한컴오피스의 [HWPX 포맷](https://www.hancom.com/)을 순수 Python으로 다루는 라이브러리입니다.
84
+ 한/글 설치 없이, OS에 관계없이 HWPX 문서의 구조를 파싱하고 콘텐츠를 조작할 수 있습니다.
85
+
86
+ > **pyhwpx / pyhwp와 다른 점?**
87
+ > `pyhwpx`는 Windows COM 자동화 기반이라 한/글이 설치된 Windows에서만 동작합니다.
88
+ > `pyhwp`는 레거시 `.hwp`(v5 바이너리) 전용입니다.
89
+ > `python-hwpx`는 OWPML/OPC 기반 `.hwpx`를 직접 파싱하므로 **Linux, macOS, CI 환경 어디서든** 동작합니다.
90
+
91
+ ## 설치
92
+
93
+ ```bash
94
+ pip install python-hwpx
95
+ ```
96
+
97
+ > 유일한 의존성은 `lxml`입니다.
98
+
99
+ ## Quick Start
100
+
101
+ ```python
102
+ from hwpx.document import HwpxDocument
103
+
104
+ # 기존 문서 열기
105
+ doc = HwpxDocument.open("보고서.hwpx")
106
+
107
+ # 빈 문서 새로 만들기
108
+ doc = HwpxDocument.new()
109
+
110
+ # 문단 추가
111
+ doc.add_paragraph("python-hwpx로 생성한 문단입니다.")
112
+
113
+ # 표 추가 (2×3)
114
+ table = doc.add_table(rows=2, cols=3)
115
+ table.set_cell_text(0, 0, "이름")
116
+ table.set_cell_text(0, 1, "부서")
117
+ table.set_cell_text(0, 2, "연락처")
118
+
119
+ # 메모 추가 (한/글에서 바로 표시)
120
+ paragraph = doc.paragraphs[0]
121
+ doc.add_memo_with_anchor("검토 필요", paragraph=paragraph)
122
+
123
+ # 저장
124
+ doc.save("결과물.hwpx")
125
+ ```
126
+
127
+ ## 주요 기능
128
+
129
+ ### 📄 문서 편집
130
+
131
+ 문단, 표, 메모, 머리말/꼬리말을 Python 객체로 다룹니다.
132
+
133
+ ```python
134
+ # 머리말·꼬리말
135
+ doc.set_header_text("기밀 문서", page_type="BOTH")
136
+ doc.set_footer_text("— 1 —", page_type="BOTH")
137
+
138
+ # 표 셀 병합·분할
139
+ table.merge_cells(0, 0, 1, 1) # (0,0)~(1,1) 병합
140
+ table.set_cell_text(0, 0, "병합된 셀", logical=True, split_merged=True)
141
+ ```
142
+
143
+ ### 🔍 텍스트 추출 & 검색
144
+
145
+ ```python
146
+ from hwpx import TextExtractor, ObjectFinder
147
+
148
+ # 텍스트 추출
149
+ for section in TextExtractor("문서.hwpx"):
150
+ for para in section.paragraphs:
151
+ print(para.text)
152
+
153
+ # 특정 객체 탐색
154
+ for obj in ObjectFinder("문서.hwpx").find("tbl"):
155
+ print(obj.tag, obj.attributes)
156
+ ```
157
+
158
+ ### 🎨 스타일 기반 텍스트 치환
159
+
160
+ 서식(색상, 밑줄, charPrIDRef)으로 런을 필터링해 선택적으로 교체합니다.
161
+
162
+ ```python
163
+ # 빨간색 텍스트만 찾아서 치환
164
+ doc.replace_text_in_runs(
165
+ "임시", "확정",
166
+ text_color="#FF0000",
167
+ )
168
+
169
+ # 특정 서식의 런 검색
170
+ runs = doc.find_runs_by_style(underline_type="SINGLE")
171
+ ```
172
+
173
+ ### 🏗️ 저수준 XML 제어
174
+
175
+ OWPML 스키마에 매핑된 데이터클래스로 XML 구조를 직접 다룹니다.
176
+
177
+ ```python
178
+ # 헤더 참조 목록
179
+ doc.border_fills # 테두리 채우기
180
+ doc.bullets # 글머리표
181
+ doc.styles # 스타일
182
+ doc.track_changes # 변경 추적
183
+
184
+ # 바탕쪽·이력·버전 파트
185
+ doc.master_pages
186
+ doc.histories
187
+ doc.version
188
+ ```
189
+
190
+ ## 아키텍처
191
+
192
+ ```
193
+ python-hwpx
194
+ ├── hwpx.document # 고수준 편집 API (HwpxDocument)
195
+ ├── hwpx.package # OPC 컨테이너 읽기/쓰기
196
+ ├── hwpx.oxml # OWPML XML ↔ 데이터클래스 매핑
197
+ │ ├── document.py # 섹션, 문단, 표, 런, 메모
198
+ │ ├── header.py # 헤더 참조 목록 (스타일, 글머리표, 변경추적 등)
199
+ │ └── body.py # 타입이 지정된 본문 모델
200
+ ├── hwpx.tools
201
+ │ ├── text_extractor # 텍스트 추출 파이프라인
202
+ │ ├── object_finder # 객체 탐색 유틸리티
203
+ │ └── validator # 스키마 유효성 검사 (hwpx-validate CLI)
204
+ └── hwpx.templates # 내장 빈 문서 템플릿
205
+ ```
206
+
207
+ ## CLI
208
+
209
+ ```bash
210
+ # HWPX 문서 스키마 유효성 검사
211
+ hwpx-validate 문서.hwpx
212
+ ```
213
+
214
+ ## 문서
215
+
216
+ | | |
217
+ |---|---|
218
+ | **[📖 전체 문서](https://airmang.github.io/python-hwpx/)** | Sphinx 기반 API 레퍼런스, 사용 가이드, FAQ |
219
+ | **[🚀 빠른 시작](https://airmang.github.io/python-hwpx/quickstart.html)** | 5분 안에 HWPX 문서 다루기 |
220
+ | **[📚 사용 가이드](https://airmang.github.io/python-hwpx/usage.html)** | 50+ 실전 사용 패턴 |
221
+ | **[🔧 API 레퍼런스](https://airmang.github.io/python-hwpx/api_reference.html)** | 클래스·메서드 상세 명세 |
222
+ | **[📐 스키마 개요](https://airmang.github.io/python-hwpx/schema-overview.html)** | OWPML 스키마 구조 설명 |
223
+
224
+ ## 요구 사항
225
+
226
+ - Python 3.10+
227
+ - lxml ≥ 4.9
228
+
229
+ ## 알려진 제약
230
+
231
+ `add_shape()` / `add_control()`은 한/글이 요구하는 모든 하위 요소를 생성하지 않습니다.
232
+ 복잡한 개체를 추가할 때는 한/글에서 열어 검증해 주세요.
233
+
234
+ ## 기여하기
235
+
236
+ 버그 리포트, 기능 제안, PR 모두 환영합니다.
237
+ 개발 환경 설정과 테스트 방법은 [CONTRIBUTING.md](CONTRIBUTING.md)를 참고하세요.
238
+
239
+ ```bash
240
+ git clone https://github.com/airmang/python-hwpx.git
241
+ cd python-hwpx
242
+ pip install -e ".[dev]"
243
+ pytest
244
+ ```
245
+
246
+ ## License
247
+
248
+ [MIT](LICENSE) © 고규현 (Kyuhyun Koh)
249
+
250
+ <br>
251
+
252
+ ## Author
253
+
254
+ **고규현** — 광교고등학교 정보·컴퓨터 교사
255
+
256
+ - ✉️ [kokyuhyun@hotmail.com](mailto:kokyuhyun@hotmail.com)
257
+ - 🐙 [@airmang](https://github.com/airmang)
@@ -1,5 +1,5 @@
1
1
  hwpx/__init__.py,sha256=RZ4O84G3Zp_L8ELArtwO3KVPvhx1vLYyKC2Ka1M5mwc,857
2
- hwpx/document.py,sha256=5M52LTdVs-0xedchpC0D254GRmMZyoe5hC3xmsg3fH0,31074
2
+ hwpx/document.py,sha256=wSyhpMs43u7XtrvdsbHVEe-50zuuFcOFO9Yx7RNG1Iw,31109
3
3
  hwpx/package.py,sha256=GQ6QXMOvmNd8Oh_P8yDGTx8GfoA5RXAPgDEZ7pc_JDw,716
4
4
  hwpx/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  hwpx/templates.py,sha256=kZ_gV0bP-DIvr5CJuzs-uGnt8XVncJCI3cGFq083uTg,1149
@@ -25,9 +25,9 @@ hwpx/tools/text_extractor.py,sha256=r2OJRgDOiR6n14hXRcvkYuSFtEHpAV6jasHv-ZLHx1Y,
25
25
  hwpx/tools/validator.py,sha256=KThqBQKKQfZkuLMGtzONbPkzy877-2FgT22FHPmt_gI,5979
26
26
  hwpx/tools/_schemas/header.xsd,sha256=mJXuFMuHGT1JnFFaluUpYUglwjMCNlfbFCRVM26eHXE,664
27
27
  hwpx/tools/_schemas/section.xsd,sha256=MgvavVHG05RDfUnVPxVU10H4FQOja5ON04_m9Uk_m7E,522
28
- python_hwpx-2.0.dist-info/licenses/LICENSE,sha256=3F1-JUTcmjmxMpHGeB77ZzaSdhms3h8p1DBBa3lvV08,1609
29
- python_hwpx-2.0.dist-info/METADATA,sha256=pHaKEvAgP1no8NoiYrlLsoOIRdUVB9NGYRVhwzzq7cU,9730
30
- python_hwpx-2.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
31
- python_hwpx-2.0.dist-info/entry_points.txt,sha256=wBO_QZkkQ0FIyAxBhJ08EAtv2SmBnN1xabRHE5G2CyM,60
32
- python_hwpx-2.0.dist-info/top_level.txt,sha256=R1iToqDh80Nf2oQhRjTN0rbN2X6kyDUizIocZjkhuxc,5
33
- python_hwpx-2.0.dist-info/RECORD,,
28
+ python_hwpx-2.1.dist-info/licenses/LICENSE,sha256=3F1-JUTcmjmxMpHGeB77ZzaSdhms3h8p1DBBa3lvV08,1609
29
+ python_hwpx-2.1.dist-info/METADATA,sha256=CDBzL--GlObsymJiTz-KL47evlZeZmz1Wfo70UiOdXs,9142
30
+ python_hwpx-2.1.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
31
+ python_hwpx-2.1.dist-info/entry_points.txt,sha256=wBO_QZkkQ0FIyAxBhJ08EAtv2SmBnN1xabRHE5G2CyM,60
32
+ python_hwpx-2.1.dist-info/top_level.txt,sha256=R1iToqDh80Nf2oQhRjTN0rbN2X6kyDUizIocZjkhuxc,5
33
+ python_hwpx-2.1.dist-info/RECORD,,
@@ -1,167 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: python-hwpx
3
- Version: 2.0
4
- Summary: Hancom HWPX 패키지를 로드하고 편집하기 위한 Python 유틸리티 모음
5
- Author: python-hwpx Maintainers
6
- License: Non-Commercial License
7
-
8
- Copyright (c) 2024 python-hwpx Maintainers
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy
11
- of this software and associated documentation files (the "Software"), to use,
12
- copy, modify, merge, publish, distribute, and sublicense the Software only for
13
- non-commercial purposes, subject to the following conditions:
14
-
15
- 1. Non-Commercial Use Only. The Software may be used, copied, modified,
16
- merged, published, distributed, and sublicensed only for non-commercial
17
- purposes. "Non-Commercial" means use that is not primarily intended for or
18
- directed toward commercial advantage, monetary compensation, or any form of
19
- direct or indirect commercial exploitation.
20
-
21
- 2. Attribution. The above copyright notice and this permission notice shall be
22
- included in all copies or substantial portions of the Software.
23
-
24
- 3. No Warranty of Commercial Support. The maintainers are not obligated to
25
- provide commercial support, maintenance, or updates.
26
-
27
- THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
- FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL THE
30
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
- SOFTWARE.
34
-
35
- If you require permissions to use this Software for commercial purposes,
36
- please contact the copyright holders to negotiate an alternative licensing
37
- arrangement.
38
-
39
- Project-URL: Homepage, https://github.com/airmang/python-hwpx
40
- Project-URL: Documentation, https://github.com/airmang/python-hwpx/tree/main/docs
41
- Project-URL: Issues, https://github.com/airmang/python-hwpx/issues
42
- Keywords: hwp,hwpx,hancom,opc,xml
43
- Classifier: Development Status :: 3 - Alpha
44
- Classifier: Intended Audience :: Developers
45
- Classifier: License :: OSI Approved :: MIT License
46
- Classifier: Programming Language :: Python :: 3
47
- Classifier: Programming Language :: Python :: 3.10
48
- Classifier: Programming Language :: Python :: 3.11
49
- Classifier: Programming Language :: Python :: 3.12
50
- Classifier: Topic :: Software Development :: Libraries
51
- Classifier: Topic :: Text Processing :: Markup :: XML
52
- Requires-Python: >=3.10
53
- Description-Content-Type: text/markdown
54
- License-File: LICENSE
55
- Requires-Dist: lxml<6,>=4.9
56
- Provides-Extra: dev
57
- Requires-Dist: build>=1.0; extra == "dev"
58
- Requires-Dist: twine>=4.0; extra == "dev"
59
- Requires-Dist: pytest>=7.4; extra == "dev"
60
- Provides-Extra: test
61
- Requires-Dist: pytest>=7.4; extra == "test"
62
- Requires-Dist: pytest-cov>=5.0; extra == "test"
63
- Provides-Extra: typecheck
64
- Requires-Dist: mypy>=1.10; extra == "typecheck"
65
- Requires-Dist: pyright>=1.1.390; extra == "typecheck"
66
- Dynamic: license-file
67
-
68
- # python-hwpx
69
-
70
- `python-hwpx`는 Hancom HWPX 문서를 읽고, 편집하고, 자동화 스크립트로 재가공하기 위한 파이썬 도구 모음입니다. Open Packaging Convention(OPC) 컨테이너를 검사하는 저수준 도구부터 문단·표·메모를 쉽게 다루는 고수준 API, 텍스트 추출과 객체 검색 유틸리티까지 하나로 제공합니다.
71
-
72
- ## 특징 요약
73
-
74
- - **패키지 로딩과 검증** – `hwpx.opc.package.HwpxPackage`로 `mimetype`, `container.xml`, `version.xml`을 확인하며 모든 파트를 메모리에 적재합니다.
75
- - **문서 편집 API** – `hwpx.document.HwpxDocument`는 문단과 표, 메모, 헤더 속성을 파이썬 객체로 노출하고 새 콘텐츠를 손쉽게 추가합니다. 섹션 머리말·꼬리말을 수정하면 `<hp:headerApply>`/`<hp:footerApply>`와 마스터 페이지 링크도 함께 갱신합니다.
76
- - **타입이 지정된 본문 모델** – `hwpx.oxml.body`는 표·컨트롤·인라인 도형·변경 추적 태그를 데이터 클래스에 매핑하고, `HwpxOxmlParagraph.model`/`HwpxOxmlRun.model`로 이를 조회·수정한 뒤 XML로 되돌릴 수 있도록 지원합니다.
77
- - **메모와 필드 앵커** – `add_memo_with_anchor()`로 메모를 생성하면서 MEMO 필드 컨트롤을 자동 삽입해 한/글에서 바로 표시되도록 합니다.
78
- - **헤더 참조 목록 탐색** – 글머리표, 문단 속성, 테두리 채우기, 스타일, 변경 추적 항목, 작성자 정보를 데이터클래스로 파싱하고 `document.border_fills`·`document.bullets`·`document.styles` 같은 조회 헬퍼로 ID 기반 검색을 단순화했습니다.
79
- - **바탕쪽·이력·버전 파트 제어** – 매니페스트에 포함된 master-page/history/version 파트를 `document.master_pages`, `document.histories`, `document.version`으로 직접 편집하고 저장합니다.
80
- - **스타일 기반 텍스트 치환** – 런 서식(색상, 밑줄, `charPrIDRef`)으로 필터링해 텍스트를 선택적으로 교체하거나 삭제합니다. 하이라이트
81
- 마커나 태그로 분리된 문자열도 서식을 유지한 채 치환합니다.
82
- - **텍스트 추출 파이프라인** – `hwpx.tools.text_extractor.TextExtractor`는 하이라이트, 각주, 컨트롤을 원하는 방식으로 표현하며 문단 텍스트를 반환합니다.
83
- - **풍부한 문서** – 빠른 시작, 50개의 사용 패턴, 설치/FAQ/스키마 개요를 Sphinx 기반 웹 문서로 제공합니다.
84
-
85
- ## 설치
86
-
87
- PyPI에서 최신 버전을 바로 설치할 수 있습니다.
88
-
89
- ```bash
90
- python -m pip install python-hwpx
91
- ```
92
-
93
- 개발 버전이나 문서 빌드를 직접 수정하려면 저장소를 클론한 뒤 편집 가능한 설치를 사용하세요.
94
-
95
- ```bash
96
- git clone https://github.com/<your-org>/python-hwpx.git
97
- cd python-hwpx
98
- python -m pip install -e .[dev]
99
- ```
100
-
101
- Sphinx 문서는 `docs/` 아래에 있으며, `python -m pip install -r docs/requirements.txt` 후 `make -C docs html`로 로컬 미리보기가 가능합니다.
102
-
103
- ## 5분 안에 맛보기
104
-
105
- ```python
106
- from io import BytesIO
107
-
108
- from hwpx import HwpxDocument
109
- from hwpx.templates import blank_document_bytes
110
-
111
- # 1) 빈 템플릿으로 문서 열기
112
- source = BytesIO(blank_document_bytes())
113
- document = HwpxDocument.open(source)
114
- print("sections:", len(document.sections))
115
-
116
- # 2) 문단과 표, 메모 추가
117
- section = document.sections[0]
118
- paragraph = document.add_paragraph("자동 생성한 문단", section=section)
119
- # 표에 사용할 기본 실선 테두리 채우기가 없으면 add_table()이 자동으로 생성합니다.
120
- table = document.add_table(rows=2, cols=2, section=section)
121
- table.set_cell_text(0, 0, "항목")
122
- table.set_cell_text(0, 1, "값")
123
- table.set_cell_text(1, 0, "문단 수")
124
- table.set_cell_text(1, 1, str(len(document.paragraphs)))
125
- document.add_memo_with_anchor("배포 전 검토", paragraph=paragraph, memo_shape_id_ref="0")
126
-
127
- # 3) 다른 이름으로 저장
128
- document.save_to_path("output/example.hwpx")
129
- ```
130
-
131
- `HwpxDocument.add_table()`은 문서에 정의된 테두리 채우기가 없으면 헤더 참조 목록에 "기본 실선" `borderFill`을 만들어 표와 모든 셀에 참조를 연결합니다.
132
-
133
- 표 셀 텍스트를 편집하는 `table.set_cell_text()`는 기존 단락에 남아 있는 `lineSegArray`와 같은 줄 배치 캐시를 제거하여 한/글이 문서를 다시 열 때 줄바꿈을 새로 계산하도록 합니다. 병합된 표 구조를 다뤄야 한다면 `table.iter_grid()` 또는 `table.get_cell_map()`으로 논리 격자와 실제 셀의 매핑을 확인하고, `set_cell_text(..., logical=True, split_merged=True)`로 논리 좌표 기반 편집과 자동 병합 해제를 동시에 처리할 수 있습니다.
134
-
135
- 더 많은 실전 패턴은 [빠른 시작](docs/quickstart.md)과 [사용 가이드](docs/usage.md)의 "빠른 예제 모음"에서 확인할 수 있습니다.
136
-
137
- ### 저장 API 변경 안내
138
-
139
- `HwpxDocument`는 저장 사용 케이스를 다음처럼 분리해 제공합니다.
140
-
141
- - `save_to_path(path) -> str | PathLike[str]`: 지정한 경로로 저장하고 같은 경로를 반환
142
- - `save_to_stream(stream) -> BinaryIO`: 파일/버퍼 스트림에 저장하고 같은 스트림을 반환
143
- - `to_bytes() -> bytes`: 메모리에서 직렬화한 바이트를 반환
144
-
145
- 기존 `save()`는 하위 호환을 위해 유지되지만 deprecated 경고를 발생시킵니다. 새 코드에서는 위 3개 메서드 사용을 권장합니다.
146
-
147
-
148
- ## 문서
149
- [사용법](https://airmang.github.io/python-hwpx/)
150
-
151
- ## 예제와 도구
152
-
153
- - `examples/` 디렉터리는 텍스트 추출, 객체 검색, QA 체크리스트 생성 예제를 제공합니다. PyPI 패키지에는 포함되지 않으므로 필요하면 저장소를 클론하거나 웹 문서의 코드 스니펫을 활용하세요.
154
- - `hwpx.templates.blank_document_bytes()`는 추가 리소스 없이 빈 HWPX 문서를 만들 수 있는 내장 템플릿을 제공합니다.
155
-
156
- ## 알려진 제약
157
-
158
- - `add_shape()`/`add_control()`은 한/글이 요구하는 모든 하위 요소를 생성하지 않으므로, 복잡한 개체를 추가할 때는 편집기에서 열어 검증해 주세요.
159
-
160
- ## 기여하기
161
-
162
- 버그 리포트와 개선 제안은 언제나 환영합니다. 개발 환경 설정과 테스트 방법은 [CONTRIBUTING.md](CONTRIBUTING.md)를 참고하세요.
163
-
164
- ## 라이선스와 연락처
165
-
166
- - 라이선스: [LICENSE](LICENSE)
167
- - 문의: 이슈 트래커 또는 kokyuhyun@hotmail.com