用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')
浙公网安备 33010602011771号