D:\python\demo.xlsx 如下:
>>> import openpyxl >>> excel=openpyxl.load_workbook('D:\\python\\demo.xlsx') >>> sheet=excel['Sheet1'] >>> sheet.row_dimensions[1].height=100 >>> sheet.column_dimensions['A'].width=100 >>> excel.save('D:\\python\\demo.xlsx')
结果如图所示:
D:\python\demo.xlsx文件如下:
>>> import openpyxl >>> excel=openpyxl.load_workbook('D:\\python\\demo.xlsx') >>> sheet=excel['Sheet1'] >>> sheet.merge_cells('A1:C1') >>> excel.save('D:\\python\\demo.xlsx')
合并后的结果如下:
>>> import openpyxl >>> excel=openpyxl.load_workbook('D:\\python\\demo.xlsx') >>> sheet=excel['Sheet1'] >>> sheet.unmerge_cells('A1:C1') >>> excel.save('D:\\python\\demo.xlsx')
拆分后结果如下: