def Set_excel_style(file_name): #设置表格为文本格式
wb = load_workbook(f'{file_name}') # 打开文件
ws = wb['Sheet1'] # 打开表格
for row in ws.rows: # 获取所有行
for cell in row: # 获取所有行中的每一个单元格
cell.font = Font(name=u'微软雅黑', size=11) # 设置字体
cell.border = Border(left=Side(border_style="thin", color='000000'),
right=Side(border_style="thin", color='000000'),
top=Side(border_style="thin", color='000000'),
bottom=Side(border_style="thin", color='000000')) # 设置边框格式
cell.alignment = Alignment(horizontal='center') # 设置居中
cell.number_format = '@' # 设置为文本格式
wb.save(f'{file_name}') # 保存文件
|