forked from Dawn_Ocean/ZJUEVA-Reimburse
修改图片排布样式
parent
d474244957
commit
66e8aab4dc
16
main.py
16
main.py
|
|
@ -32,7 +32,7 @@ def gen_filelist(pages, path = os.path.abspath('.')):
|
||||||
page_curr = 1
|
page_curr = 1
|
||||||
type_curr = 0
|
type_curr = 0
|
||||||
for filename in file_list:
|
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 []
|
return []
|
||||||
else:
|
else:
|
||||||
type_curr += 1
|
type_curr += 1
|
||||||
|
|
@ -55,10 +55,18 @@ def gen_docx():
|
||||||
if len(file_list) != 0:
|
if len(file_list) != 0:
|
||||||
pic_count = 0
|
pic_count = 0
|
||||||
for filename in file_list:
|
for filename in file_list:
|
||||||
doc.add_picture(filename, height = Inches(2.5))
|
|
||||||
pic_count += 1
|
pic_count += 1
|
||||||
if pic_count % 3 == 0 and pic_count != len(file_list):
|
if pic_count % 3 == 1:
|
||||||
doc.add_page_break()
|
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:
|
else:
|
||||||
print("请检查文件命名是否正确!")
|
print("请检查文件命名是否正确!")
|
||||||
doc.save("output.docx")
|
doc.save("output.docx")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue