from openpyxl import load_workbook
workbook = load_workbook(filename = "myexcel.xlsx")
wsw = workbook.active
print("展示myexcel.xlsx中有几个sheet:",workbook.sheetnames)
可以做个表头
可以通过指定单元格的形式来写入指定表头
`wsw[‘A1’] = ‘电话号码’
wsw[‘B1’] = ‘姓名’
wsw[‘C1’] = ‘住宿地址’
wsw[‘D1’] = ‘电脑’
wsw[‘E1’] = ‘id’``
从one.xlsx中获取数据
wb= openpyxl.load_workbook('one.xlsx')
指定sheet中找到数据
sh = wb['Sheet1']
利用for循环进行遍历一一展示
for cases in list(sh.rows)[1:]:
number = cases[0].value
name = cases[1].value
address = cases[2].value
pc = cases[3].value
idl = cases[4].value
将上面遍历出来的数据进行插入上面添加表头的信息的下面
wsw.append([number,name,address,pc,idl])
把数据都保存在myexcel中
workbook.save(filename="myexcel.xlsx")