1、word表格样式的设置
from docx import *
document = Document()
table = document.add_table(3, 3, style="Medium Grid 1 Accent 1")
heading_cells = table.rows[0].cells
heading_cells[0].text = '第一列内容'
heading_cells[1].text = '第二列内容'
heading_cells[2].text = '第三列内容'
document.save(r"d:\demo.docx")
2、获取所有word表格样式
from docx.enum.style import WD_STYLE_TYPE
from docx import *
document = Document()
styles = document.styles
#生成所有表样式
for s in styles:
if s.type == WD_STYLE_TYPE.TABLE:
document.add_paragraph("表格样式 : "+ s.name)
table = document.add_table(3,3, style = s)
heading_cells = table.rows[0].cells
heading_cells[0].text = '第一列内容'
heading_cells[1].text = '第二列内容'
heading_cells[2].text = '第三列内容'
document.add_paragraph("\n")
document.save('demo2.docx')
表格样式整理如下:
0 | Normal Table | |
1 | Table Grid | |
2 | Light Shading | |
3 | Light Shading Accent 1 | |
4 | Light Shading Accent 2 | |
5 | Light Shading Accent 3 | |
6 | Light Shading Accent 4 | |
7 | Light Shading Accent 5 | |
8 | Light Shading Accent 6 | |
9 | Light List | |
10 | Light List Accent 1 | |
11 | Light List Accent 2 | |
12 | Light List Accent 3 | |
13 | Light List Accent 4 | |
14 | Light List Accent 5 | |
15 | Light List Accent 6 | |
16 | Light Grid | |
17 | Light Grid Accent 1 | |
18 | Light Grid Accent 2 | |
19 | Light Grid Accent 3 | |
20 | Light Grid Accent 4 | |
21 | Light Grid Accent 5 | |
22 | Light Grid Accent 6 | |
23 | Medium Shading 1 | |
24 | Medium Shading 1 Accent 1 | |
25 | Medium Shading 1 Accent 2 | |
26 | Medium Shading 1 Accent 3 | |
27 | Medium Shading 1 Accent 4 | |
28 | Medium Shading 1 Accent 5 | |
29 | Medium Shading 1 Accent 6 | |
30 | Medium Shading 2 | |
31 | Medium Shading 2 Accent 1 | |
32 | Medium Shading 2 Accent 2 | |
33 | Medium Shading 2 Accent 3 | |
34 | Medium Shading 2 Accent 4 | |
35 | Medium Shading 2 Accent 5 | |
36 | Medium Shading 2 Accent 6 | |
37 | Medium List 1 | |
38 | Medium List 1 Accent 1 | |
39 | Medium List 1 Accent 2 | |
40 | Medium List 1 Accent 3 | |
41 | Medium List 1 Accent 4 | |
42 | Medium List 1 Accent 5 | |
43 | Medium List 1 Accent 6 | |
44 | Medium List 2 | |
45 | Medium List 2 Accent 1 | |
46 | Medium List 2 Accent 2 | |
47 | Medium List 2 Accent 3 | |
48 | Medium List 2 Accent 4 | |
49 | Medium List 2 Accent 5 | |
50 | Medium List 2 Accent 6 | |
51 | Medium Grid 1 | |
52 | Medium Grid 1 Accent 1 | |
53 | Medium Grid 1 Accent 2 | |
54 | Medium Grid 1 Accent 3 | |
55 | Medium Grid 1 Accent 4 | |
56 | Medium Grid 1 Accent 5 | |
57 | Medium Grid 1 Accent 6 | |
58 | Medium Grid 2 | |
59 | Medium Grid 2 Accent 1 | |
60 | Medium Grid 2 Accent 2 | |
61 | Medium Grid 2 Accent 3 | |
62 | Medium Grid 2 Accent 4 | |
63 | Medium Grid 2 Accent 5 | |
64 | Medium Grid 2 Accent 6 | |
65 | Medium Grid 3 | |
66 | Medium Grid 3 Accent 1 | |
67 | Medium Grid 3 Accent 2 | |
68 | Medium Grid 3 Accent 3 | |
69 | Medium Grid 3 Accent 4 | |
70 | Medium Grid 3 Accent 5 | |
71 | Medium Grid 3 Accent 6 | |
72 | Dark List | |
73 | Dark List Accent 1 | |
74 | Dark List Accent 2 | |
75 | Dark List Accent 3 | |
76 | Dark List Accent 4 | |
77 | Dark List Accent 5 | |
78 | Dark List Accent 6 | |
79 | Colorful Shading | |
80 | Colorful Shading Accent 1 | |
81 | Colorful Shading Accent 2 | |
82 | Colorful Shading Accent 3 | |
83 | Colorful Shading Accent 4 | |
84 | Colorful Shading Accent 5 | |
85 | Colorful Shading Accent 6 | |
86 | Colorful List | |
87 | Colorful List Accent 1 | |
88 | Colorful List Accent 2 | |
89 | Colorful List Accent 3 | |
90 | Colorful List Accent 4 | |
91 | Colorful List Accent 5 | |
92 | Colorful List Accent 6 | |
93 | Colorful Grid | |
94 | Colorful Grid Accent 1 | |
95 | Colorful Grid Accent 2 | |
96 | Colorful Grid Accent 3 | |
97 | Colorful Grid Accent 4 | |
98 | Colorful Grid Accent 5 | |
99 | Colorful Grid Accent 6 |
##########################