-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest_docx_layout.py
59 lines (46 loc) · 1.78 KB
/
test_docx_layout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import docx
def show_sec(sec):
print("---sec info---")
print("page height", sec.page_height)
print("page width", sec.page_width)
print("page left margin", sec.left_margin)
print("page right margin", sec.right_margin)
print("page top margin", sec.top_margin)
print("page bottom margin", sec.bottom_margin)
def show_para(para, doc):
print("\n\n---para info---")
print("para style", para.style.name)
font = doc.styles[para.style.name].font
print("para font", font.name, font.size)
print("align", para.paragraph_format.alignment)
print("left indent", para.paragraph_format.left_indent)
print("right indent", para.paragraph_format.right_indent)
print("first line indent", para.paragraph_format.first_line_indent)
print("line space", para.paragraph_format.line_spacing)
print("space before", para.paragraph_format.space_before)
print("space after", para.paragraph_format.space_after)
def show_run_info(run, doc):
print("---run info---")
print("run style", [run.style.type, run.style.name, run.style.font.size])
print("run part", run.part)
print("run element", run.element)
print("run font name", run.font.name)
print("run font size", run.font.size)
def test(document):
print("-------------DEBUG---------")
secs = document.sections
for sec in secs:
show_sec(sec)
paras = document.paragraphs
for para in paras:
show_para(para, document)
for run in para.runs:
show_run_info(run, document)
print("run.text", [run.text])
styles = document.styles
for s in styles:
print("style", s)
print("---------------")
core_properties = document.core_properties
for idx, uu in enumerate(dir(core_properties)[27:]):
print(idx, uu)