๋ฐ์ํ
Demo.docx ํ์ผ์ ์ด์ด์ ํธ์งํด๋ณด๊ธฐ
from docx import Document
from docx.enum.table import WD_ALIGN_VERTICAL
from docx.enum.text import WD_ALIGN_PARAGRAPH
document = Document('Demo.docx')
# ๋ฌธ์๋ด์ ํ
์ด๋ธ๋ค
tables = document.tables
# 1๋ฒ์งธ ํ
์ด๋ธ 0, 0 ์
- 2๋ฒ์งธ paragraphs์ ์
๋ ฅ
tables[0].cell(0, 0).paragraphs[1].text = 'paragraphs[1]'
# 2๋ฒ์งธ ํ
์ด๋ธ 0, 0 ์
์ ์
๋ ฅ
tables[1].cell(0, 0).text = 'table[1] (0,0)'
out_file = 'New.docx'
document.save(out_file)
ํ์ ๋ฐ์ดํฐ ์ ๋ ฅ ๋ฐฉ๋ฒ
1.
tables[0].rows[0].cells[3].paragraphs[0].text = "test"
tables[0].rows[0].cells[3].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.RIGHT
2. ๋๋ฒ์งธ ๋ฐฉ๋ฒ์ ํฐํธ์ ๊ตต๊ฒ, ์ดํค๋ฆญ, ๋ฐ์ค์ ์ค ์ ์๋ค๋ ์ฅ์ ์ด ์๋ค.
tables[0].rows[3].cells[3].paragraphs[0].add_run("test")
runner = tables[0].rows[3].cells[4].paragraphs[0].add_run("test4")
runner.bold = True
runner.underline = True
runner.italic = True
- ์ ํฌ๊ธฐ ์กฐ์
cells[0].width = Cm(2.9)
cells[0].height = Cm(2.9)
https://www.geeksforgeeks.org/working-with-tables-python-docx-module/
https://python-docx.readthedocs.io/en/latest/#user-guide
๋ฐ์ํ
'Python > Basic' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python] cx_Oracle ํ๊ธ ๊นจ์ง (0) | 2020.10.20 |
---|---|
[Oauth] Google, email ์ ๋ณด ์ป๊ธฐ (0) | 2020.10.09 |
[Python] openpyxl - ์์ ์ฝ๊ธฐ/ํธ์ง ํ๊ธฐ (0) | 2020.08.14 |
Streamlit. The fastest way to build custom ML tools (0) | 2020.03.25 |
[Python] __name__ (0) | 2020.03.05 |