🌤️ 加载中...
#
Python 2020-11-16

python3 新建excel写入第一行为粗体,并锁定

By Jove 3 Views 2 MIN READ 0 Comments

import openpyxl 
from openpyxl.styles import Font

create_excel = openpyxl.Workbook() #通过Workbook类创建实例,创建一个excel
excel_sheet = create_excel.active  #激活excel,类似鼠标打开excel
excel_sheet.tltle = "sheet_test"   #重命名sheet名字为sheet_test
excel_sheet.freeze_panes = 'A2'    #锁定(固定)第一行
first_row = ['ID','名字','姓名','性别','年龄','身高','爱好'] #写入标题行名称
for i in range(len(first_row)):
      excel_sheet.cell(1,(i+1),first_row[i]).font = Font(name='微软雅黑',bold=True,size=13) #字体加粗,13
create_excel.save('test.xlsx')
create_excel.close()

本文由 Jove 原创

采用 CC BY-NC-SA 4.0 协议进行许可

转载请注明出处:https://www.jozxing.cc/index.php/archives/2201/

TAGS: 无标签

相关推荐

  • 暂无相关推荐,看看别的吧。

0 评论