python-tools/file.py
2024-07-22 15:47:40 +09:00

38 lines
1.2 KiB
Python

import datetime,xlwt,os
import logging
from rich.logging import RichHandler
FORMAT = "%(message)s"
logging.basicConfig(
level="NOTSET", format=FORMAT, datefmt="[%Y-%m-%d %H:%d]", handlers=[RichHandler()]
)
log = logging.getLogger("rich")
today = datetime.date.today()
format = today.strftime("%Y%m%d")
path = "/home/wjf/2023测试excel/"
full_path = path + format
try:
if not os.path.exists(full_path) :
os.makedirs(full_path)
logging.info("创建目录:" + full_path)
else:
logging.info("目录已存在:" + full_path)
for item in range(4):
workbook = xlwt.Workbook('utf-8')
worksheet = workbook.add_sheet("sheet %s" %item)
worksheet.write(0,0, '修正前')
worksheet.write(0,1,'修正後')
filename = "{item}_確認エビデンス({date}).xlsx".format(date=format, item=item)
if os.path.exists(full_path + "/" + filename):
logging.info("\[[red]跳过创建[/]] " +"文件已存在:" + filename, extra={"markup": True})
else:
workbook.save(full_path + "/" + filename)
logging.info("\[[green]创建成功[/]] " +"创建文件:" + filename, extra={"markup": True})
except Exception as e:
logging.exception(e)