import openpyxl |
# 打开 Excel 文件 |
workbook = openpyxl.load_workbook( 'example.xlsx' ) |
# 选择工作表 |
sheet = workbook[ 'Sheet1' ] |
# 合并单元格 |
sheet.merge_cells( 'A1:B2' ) |
# 取消合并单元格 |
sheet.unmerge_cells( 'A1:B2' ) |
# 保存 Excel 文件 |
workbook.save( 'example.xlsx' ) |