水木社区手机版
首页
|版面-Python的自由天空(Python)|
新版wap站已上线
返回
1/1
|
转到
主题:python 操作word表格,用docx,如何合并单元格?
楼主
|
feng321
|
2022-01-14 09:04:56
|
只看此ID
from docx import Document
doc = Document()
table = doc.add_table(6,6)
header_row = table.rows[0]
header_row.merge_cells(0,3)
doc.save('合并单元格.docx')
这样,会报错:
Traceback (most recent call last):
File "D:/myProgram/pythonProgram/JetbrainsCrack/excelToMssql/从excel导入到word/合并单元格.py", line 6, in <module>
header_row.merge_cells(0,3)
AttributeError: '_Row' object has no attribute 'merge_cells'
谁有好法子,合并word表格的单元格吗?这个错误,在baidu、google都搜索,都没有搜到相同错误的
--
FROM 120.242.253.*
1楼
|
feng321
|
2022-01-14 17:09:23
|
只看此ID
有大神指导一下吗?
--
FROM 120.242.253.*
2楼
|
callmebbser
|
2022-01-14 18:54:00
|
只看此ID
row object没有merge方法,cell object才有merge方法:
https://python-docx.readthedocs.io/en/latest/api/table.html#id1
table = doc.add_table(6,6)
cell0 = table.cell(0,0)
cell3 = table.cell(0,3)
cell0.merge(cell3)
【 在 feng321 (sfdf) 的大作中提到: 】
: from docx import Document
: doc = Document()
: table = doc.add_table(6,6)
: ...................
--
FROM 119.233.180.*
3楼
|
callmebbser
|
2022-01-14 19:08:25
|
只看此ID
https://python-docx.readthedocs.io/en/latest/dev/analysis/features/table/cel
l-merge.html
【 在 feng321 (sfdf) 的大作中提到: 】
: 有大神指导一下吗?
--
FROM 119.233.180.*
4楼
|
feng321
|
2022-01-14 19:13:20
|
只看此ID
谢谢,确实是这样的。table.cell(3, 1).merge(table.cell(3, 3))
【 在 callmebbser 的大作中提到: 】
: row object没有merge方法,cell object才有merge方法:
:
https://python-docx.readthedocs.io/en/latest/api/table.html#id1
: table = doc.add_table(6,6)
: ...................
--
FROM 120.242.253.*
1/1
|
转到
选择讨论区
首页
|
分区
|
热推
BYR-Team
©
2010.
KBS Dev-Team
©
2011
登录完整版