使用openpyxl
wb = openpyxl.load_workbook('全国高校名单.xlsx')
sheet = wb.active
sheet.freeze_panes = 'A4'
wb.save('freeze.xlsx')
使用xlwings
import xlwings as xw
wb = xw.books.active
active_window = wb.app.api.ActiveWindow
active_window.FreezePanes = False
active_window.SplitColumn = 4 # 冻结至哪一列
active_window.SplitRow = 1 # 冻结至哪一行
active_window.FreezePanes = True
使用xlwt
# 设置冻结窗口
# 设置冻结为真
work_sheet.set_panes_frozen('1')
# 水平冻结
work_sheet.set_horz_split_pos(2)
# 垂直冻结
work_sheet.set_vert_split_pos(1)
设置冻结窗口需先将sheet表的冻结属性设置为真,然后再对水平、垂直需冻结行数、列数进行设置。