1. 加载excel文件,设置单元格值,设置字体
from openpyxl.cell import Cell from openpyxl.styles import Font from openpyxl.worksheet.worksheet import Worksheet from openpyxl import Workbook, load_workbook wb: Workbook = load_workbook(file) # 获取第一个sheet页 sheet: Worksheet = wb[wb.sheetnames[0]] # 获取最大列数 max_col = sheet.max_column # 设置单元格的值 cell: Cell = sheet.cell(1, max_col + 1, "aaaa") # 设置字体 cell.font = Font(size=12, bold=True, color="FF0000")