我想用这个 (https://python-docx.readthedocs.io/en/latest/dev/analysis/features/shapes/picture.html?highlight=picture#candidate-protocol)将一张图片插入到表格中,但结果是出现此错误:
AttributeError:“运行”对象没有属性“ add_inline_picture”
这是我的代码:
from docx import Document
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.shared import Inches
from docx.text.run import Run
document = Document()
table = document.add_table(rows = 1,cols = 1)
cell = table.rows[0].cells
# print(cell)
paragraph = cell[0].paragraphs[0]
# print(paragraph)
paragraph. alinement = WD_ALIGN_PARAGRAPH.CENTER
run = paragraph.add_run()
# print(run)
inline_shape = run.add_inline_picture("snapshotpie_1.png",MIME_type =
None)
inline_shape.width = Inches(5.5)
inline_shape.height = Inches(5.5)
document.save("table_cell_pic.docx")