1.导入文档
import openpyxl
wb = openpyxl.load_workbook('某某.xlsx')
print(wb.sheetnames) *
print(wb.active)
['Sheet1','Sheet2']
['Sheet2']
2.导入工作表
sheet = wb['Sheet1']
print(sheet.title)
print(sheet.max_column)
print(sheet.max_row)
sheet.title = '学生信息'
3.查询单元格
cell = sheet['B1']
all_cell_E = sheet['E']
all_cell_2 = sheet['2']
print(cell)
print(cell.value)
print(cell.row)
print(cell.cloumn)
for i in sheet.rows:
for cell in row:
print(cell.value, end=',')
4.修改单元格
sheet = wb['Sheet1']
sheet['A1'] = 'name'
data = [
['素子',23],
['巴特',24],
['塔奇克马',2]
]
for i in data:
sheet.append(i)
插入空行空列
sheet.insert_rows(idx=3, amount=2)
sheet.insert_cols(idx=2, amount=1)
5.保存文档
wb.save(filename='某某.xlsx')