# 创建Word文档
def create_word_document(image_paths, doc_name):
doc = Document()
# 按3张图片一行进行排版
for i in range(0, len(image_paths), 3):
# 添加一个表格,3列1行
table = doc.add_table(rows=1, cols=3)
table.autofit = False
table.allow_autofit = False
# 插入图片到表格中
for j in range(3):
if i + j < len(image_paths):
cell = table.cell(0, j)
paragraph = cell.paragraphs[0]
run = paragraph.add_run()
run.add_picture(image_paths[i + j], width=Inches(2.0))
# 保存Word文档
doc.save(doc_name)
return doc_name