用openpyxl提取表格中的数据

设置文件 mingc

from openpyxl import load_workbook, Workbook

addr = "3.xlsx"

打开文件

wb = load_workbook(addr)

sheet = wb.get_sheet_by_name('iss')

r = 1
agelist = []

while True:
age = sheet["C" + str(r)].value
# id=sheet["A" + str(r)].value
wb = Workbook()
sheet2 = wb.active
# sheet2.title = "人员情况"
if age:
agelist.append(age)

if age == None:
    break
# print(age)
r += 1

blist = []
for k in range(1,len(agelist)):
blist.append(k)

adict = dict(zip(blist, agelist))
print(adict)
for id, age in adict.items():
b=str(age)
c=str(id-1)
print(c)
d=c.strip('')if id else ''
e=b.strip('') if age else ''

sheet2.cell(row=id , column=1, value=d)
sheet2.cell(row=id , column=2, value=e)

wb.save('6.xlsx')

posted @ 2019-09-16 13:09  温温温  阅读(712)  评论(0)    收藏  举报