import openpyxl
wb = openpyxl.load_workbook('pin_list.xlsx')
#print(wb.get_sheet_names())
sheet = wb.get_sheet_by_name('Sheet2')
for i in range(2,23,1):
if sheet.cell(row=i,column=2).value == 'I/O':
with open("test1.txt","a",encoding="utf-8") as f:
data1 = 'input '+sheet.cell(row=i,column=1).value +'_oe'
data2 = 'input '+sheet.cell(row=i,column=1).value +'_out'
f.write('%s\n'%(data1))
#f.write(data1)//这种也可以,只是要换行的话,需要在data上标注换行
# #f.write(data2)
# f.write("%s\n"%(data2))
elif sheet.cell(row=i,column=2).value == 'O':
with open("test1.txt","a",encoding="utf-8") as f:
data3 = 'input '+sheet.cell(row=i,column=1).value
f.write('%s \n'%(data3))
#f.write(data3)
print("it is done")
下面是表格的样子