from colorama import init
init(autoreset=True)
from openpyxl.styles import Alignment
import openpyxl as op
class Basic(object):
def save_excel(self, excel, data, sheet="Sheet"):
if os.path.exists(excel):
wb = op.load_workbook(excel)
if sheet not in wb.sheetnames:
wb.create_sheet(sheet)
ws = wb[sheet]
else:
wb = op.Workbook()
ws = wb["Sheet"]
ws.title = sheet
for row in data:
ws.append(row)
try:
wb.save(excel)
self.print_log("生成文件: {}文件{}页数据输出完成".format(excel, sheet), 1)
except Exception as e:
self.print_log("生成文件: {}文件失败,原因:{}".format(excel, e), 3)
def save_compare_excel(self, excel, data, sheet="Sheet"):
wb = op.Workbook()
ws = wb["Sheet"
【python】openpyxl写入excel不同sheet和设置自动换行
最新推荐文章于 2024-08-14 21:04:17 发布