python---word表格样式设置

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')

表格样式整理如下:

0Normal Table 
1Table Grid 
2Light Shading 
3Light Shading Accent 1 
4Light Shading Accent 2 
5Light Shading Accent 3 
6Light Shading Accent 4 
7Light Shading Accent 5 
8Light Shading Accent 6 
9Light List 
10Light List Accent 1 
11Light List Accent 2 
12Light List Accent 3 
13Light List Accent 4 
14Light List Accent 5 
15Light List Accent 6 
16Light Grid 
17Light Grid Accent 1 
18Light Grid Accent 2 
19Light Grid Accent 3 
20Light Grid Accent 4 
21Light Grid Accent 5 
22Light Grid Accent 6 
23Medium Shading 1 
24Medium Shading 1 Accent 1 
25Medium Shading 1 Accent 2 
26Medium Shading 1 Accent 3 
27Medium Shading 1 Accent 4 
28Medium Shading 1 Accent 5 
29Medium Shading 1 Accent 6 
30Medium Shading 2 
31Medium Shading 2 Accent 1 
32Medium Shading 2 Accent 2 
33Medium Shading 2 Accent 3 
34Medium Shading 2 Accent 4 
35Medium Shading 2 Accent 5 
36Medium Shading 2 Accent 6 
37Medium List 1 
38Medium List 1 Accent 1 
39Medium List 1 Accent 2 
40Medium List 1 Accent 3 
41Medium List 1 Accent 4 
42Medium List 1 Accent 5 
43Medium List 1 Accent 6 
44Medium List 2 
45Medium List 2 Accent 1 
46Medium List 2 Accent 2 
47Medium List 2 Accent 3 
48Medium List 2 Accent 4 
49Medium List 2 Accent 5 
50Medium List 2 Accent 6 
51Medium Grid 1 
52Medium Grid 1 Accent 1 
53Medium Grid 1 Accent 2 
54Medium Grid 1 Accent 3 
55Medium Grid 1 Accent 4 
56Medium Grid 1 Accent 5 
57Medium Grid 1 Accent 6 
58Medium Grid 2 
59Medium Grid 2 Accent 1 
60Medium Grid 2 Accent 2 
61Medium Grid 2 Accent 3 
62Medium Grid 2 Accent 4 
63Medium Grid 2 Accent 5 
64Medium Grid 2 Accent 6 
65Medium Grid 3 
66Medium Grid 3 Accent 1 
67Medium Grid 3 Accent 2 
68Medium Grid 3 Accent 3 
69Medium Grid 3 Accent 4 
70Medium Grid 3 Accent 5 
71Medium Grid 3 Accent 6 
72Dark List 
73Dark List Accent 1 
74Dark List Accent 2 
75Dark List Accent 3 
76Dark List Accent 4 
77Dark List Accent 5 
78Dark List Accent 6 
79Colorful Shading 
80Colorful Shading Accent 1 
81Colorful Shading Accent 2 
82Colorful Shading Accent 3 
83Colorful Shading Accent 4 
84Colorful Shading Accent 5 
85Colorful Shading Accent 6 
86Colorful List 
87Colorful List Accent 1 
88Colorful List Accent 2 
89Colorful List Accent 3 
90Colorful List Accent 4 
91Colorful List Accent 5 
92Colorful List Accent 6 
93Colorful Grid 
94Colorful Grid Accent 1 
95Colorful Grid Accent 2 
96Colorful Grid Accent 3 
97Colorful Grid Accent 4 
98Colorful Grid Accent 5 
99Colorful Grid Accent 6

 

##########################

转自:https://blog.csdn.net/ibiao/article/details/78595295

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值