xuyonghao
2024-12-31 3a3c413bd6e6fb89d80f7a9487ba9fabbd12e8bb
app/utils/excelmerge/conformity.py
@@ -1,6 +1,10 @@
from openpyxl import load_workbook
from datetime import datetime
import os
import random
import shutil
import string
from datetime import datetime
from openpyxl import load_workbook
def clear_blank_rows(sheet):
@@ -55,11 +59,24 @@
                    template_sheets[name].cell(row=i, column=1).value = i - start_row + 1
        timestamp = datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
        output_path = os.path.join(print_path, f'{timestamp}.xlsx')
        random_string = ''.join(random.choice(string.ascii_letters + string.digits) for i in range(5))
        file_name = f'{random_string}_{timestamp}'
        output_path = os.path.join(print_path, f'{file_name}.xlsx')
        template_excel.save(output_path)
        template_excel.close()
        return True
        try:
            for filename in os.listdir(file_path):
                file_path_full = os.path.join(file_path, filename)
                if os.path.isfile(file_path_full) or os.path.islink(file_path_full):
                    os.unlink(file_path_full)
                elif os.path.isdir(file_path_full):
                    shutil.rmtree(file_path_full)
            os.rmdir(file_path)
        except Exception as e:
            print(f"删除文件时发生错误: {e}")
        return file_name
    except Exception as e:
        print(f"读取数据发生错误: {e}")
        return False
        return None