openpyxl模块--------------------------合并单元格功能及冻结单元格B2

#!/usr/bin/env python

from openpyxl import Workbook
from openpyxl.styles import Alignment

book = Workbook()
sheet = book.active

sheet.merge_cells('A1:B2')

cell = sheet.cell(row=1, column=1)
cell.value = 'Sunny day'
cell.alignment = Alignment(horizontal='center', vertical='center')

book.save('merging.xlsx')

实现效果如下;

 

 

冻结代码:

from openpyxl import Workbook
from openpyxl.styles import Alignment

book = Workbook()
sheet = book.active



sheet.freeze_panes = 'B2'

book.save('freezing.xlsx')
实现效果如下
怎么都能看到2个1,证明被冻结了

 

posted @ 2023-07-25 10:14  往事已成昨天  阅读(50)  评论(0编辑  收藏  举报