import openpyxl
'''
读取有公式的excel表格
'''
wb = openpyxl.load_workbook('gongshi.xlsx',data_only=True)
ws = wb.worksheets[0]
for row in ws.rows:
print(row[3].value)
'''
调整行高和列宽,row_dimensions[1].height 调整行高,column_dimensions['B'].width 调整列宽
'''
ws.row_dimensions[1].height = 70
ws.column_dimensions['B'].width = 20
wb.save('ceshi_changkuan.xlsx')
'''
合并和拆分单元格,merge_cells 合并单元格,unmerge_cells 拆分单元格
'''
ws.merge_cells('B2:C3')
ws['B2'] = 'four cells merged together'
wb.save('ceshi_hebing.xlsx')
ws.unmerge_cells('B2:C3')
wb.save('ceshi_hebing1.xlsx')
'''
freeze_panes 冻结窗口 第一行第二行 第一列 第二列
'''
ws.freeze_panes = 'C3'
wb.save('freezeExample.xlsx')
总分
165
149
160
161
167
网友评论