문제

Python Docx 라이브러리를 사용하여 Word 문서를 조작하고 있습니다.그러나 해당 라이브러리의 문서 페이지의 센터에 선을 맞추는 방법을 찾을 수 없습니다.나는 Google에서 찾을 수 없습니다.

    from docx import Document
    document = Document()
    p = document.add_paragraph('A plain paragraph having some ')
    p.add_run('bold').bold = True
    p.add_run(' and some ')
    p.add_run('italic.').italic = True
.

DOCX의 텍스트를 어떻게 정렬 할 수 있습니까?

도움이 되었습니까?

해결책

python-docx 0.7a href="https:///github.com/python-openxml/python-docx/commit/158f2121bcd2c58b258dec1b83f8fef158dec1b83f8fef158dec1b83f8fef158de19"nofollow noreferrer"> https : // github.com / python-openxml / python-docx / commit / 158f2121bcd2c58b258dec1b83f8fef15316de19 기능 추가 # 51 : 단락 (읽기 / 쓰기) 이제 단락을 여기에 정렬 할 수 있습니다 : http://python-docx.readthedocs.org/en/latest/dev/analysis/features/par-alignment.html

 paragraph = document.add_paragraph("This is a text")
 paragraph.alignment = 0 # for left, 1 for right, 2 center, 3 justify ....
.

댓글에서 편집

실제로 그것은 왼쪽에서 0, 중앙 1, 오른쪽 2의 경우

comments

이런 코드를 강조해서는 안됩니다.WD_ALIGN_PARAGRAPH.CENTER를 사용하여 중심 등에 올바른 값을 얻으려면 다음을 수행하려면 다음 가져 오기

을 사용하십시오.
from docx.enum.text import WD_ALIGN_PARAGRAPH 
.

다른 팁

p = document.add_paragraph('A plain paragraph having some ',style='BodyText', breakbefore=False, jc='left')# @param string jc: Paragraph alignment, possible values:left, center, right, both (justified), ...
.

참조 용이 참조 at at def 단락문서

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top