1.安装openpyxl
pip install openpyxl
2.对excel进行操作
import openpyxl #引入openpyxl
# 读取excel
excel = openpyxl.load_workbook("test.xlsx")
# 获取所有的sheet
sheets = excel.get_sheet_names()
# 获取第一个sheet表
sheet = excel[sheets[0]]
# 获取sheet最大行
row = sheet.max_row
# 获取sheet最大列
column = sheet.max_column
#获取指定位置的值
sheet.cell(row=1, column=2).value
#创建新的sheet
excel.create_sheet(title=‘test’)
# 往表格内添加单行数据
value = ['hello','word','excel']
sheet.append(value)
#对指定对位置添加背景
sheet.cell(row=1, column=1).fill = PatternFill(fill_type='solid', fgColor="87CEFF")
#保存并重命名
excel.save("excel.xlsx")