修改图片排布样式

main
Dawn_Ocean 2023-10-18 17:00:33 +08:00
parent d474244957
commit 66e8aab4dc
1 changed files with 12 additions and 4 deletions

14
main.py
View File

@ -32,7 +32,7 @@ def gen_filelist(pages, path = os.path.abspath('.')):
page_curr = 1
type_curr = 0
for filename in file_list:
if int(filename[0:1]) != page_curr or filename[2] != types[type_curr % 3]:
if int(filename[0:2]) != page_curr or filename[2] != types[type_curr % 3]:
return []
else:
type_curr += 1
@ -55,9 +55,17 @@ def gen_docx():
if len(file_list) != 0:
pic_count = 0
for filename in file_list:
doc.add_picture(filename, height = Inches(2.5))
pic_count += 1
if pic_count % 3 == 0 and pic_count != len(file_list):
if pic_count % 3 == 1:
doc.add_picture(filename, height = Inches(2.5))
table = doc.add_table(rows = 1, cols = 2)
elif pic_count % 3 == 2:
cell1 = table.cell(0, 0)
cell1.paragraphs[0].add_run().add_picture(filename, height = Inches(5.0))
elif pic_count % 3 == 0:
cell2 = table.cell(0, 1)
cell2.paragraphs[0].add_run().add_picture(filename, height = Inches(5.0))
if pic_count != len(file_list):
doc.add_page_break()
else:
print("请检查文件命名是否正确!")