From 66e8aab4dc234a484d54cc86a7d011271b88eabf Mon Sep 17 00:00:00 2001 From: Dawn_Ocean <1785590531@qq.com> Date: Wed, 18 Oct 2023 17:00:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=BE=E7=89=87=E6=8E=92?= =?UTF-8?q?=E5=B8=83=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 7f17772..186bc11 100644 --- a/main.py +++ b/main.py @@ -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,10 +55,18 @@ 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): - doc.add_page_break() + 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("请检查文件命名是否正确!") doc.save("output.docx")