Я пытаюсь сохранить несколько документов в l oop, но я сохраняю только последний документ в моем списке. Как мне перестать сохранять мой документ? Думаю, это просто ошибка форматирования. Все остальные части кода работают, но последний раздел успешно создает каталог, а затем продолжает сохранять только один из восьми тестовых файлов.
Это мой код:
for i in range (4158 , 4165+1):
FSBRID = []
FSVRID = []
GHSBRID = []
GHSVRID = []
TFB=[]
TLV=[]
for j in range(94, 95):
a = ws1.cell(row=i, column=j)
if 'Transition' in a.value:
for j in range(95,96):
a = ws1.cell(row=i, column=j)
if 'Flower' in a.value or 'Leaf' in a.value:
TFB.append((ws1.cell(row=i, column=1)).value)
print('TFB:', TFB)
elif 'GH Soil' in a.value:
GHSBRID.append((ws1.cell(row=i, column=1)).value)
print('GHSBRID:', GHSBRID)
elif 'Vegetative' in a.value:
TLV.append((ws1.cell(row=i, column=1)).value)
print('TLV:', TLV)
elif 'Flower' in a.value:
for j in range(95,96):
a = ws1.cell(row=i, column=j)
if 'Leaf' in a.value:
TLV.append((ws1.cell(row=i, column=1)).value)
print('TLV:', TLV)
elif 'Flower' in a.value:
TFB.append((ws1.cell(row=i, column=1)).value)
print('TFB:', TFB)
elif 'GH Soil' in a.value:
GHSBRID.append((ws1.cell(row=i, column=1)).value)
print('GHSBRID:', GHSBRID)
elif 'Pre-Planting' in a.value:
for j in range(95, 96):
a = ws1.cell(row=i, column=j)
if 'GH Soil' in a.value:
GHSVRID.append((ws1.cell(row=i, column=1)).value)
print(GHSVRID)
elif 'Field Soil' in a.value:
FSVRID.append((ws1.cell(row=i, column=1)).value)
print(FSVRID)
elif 'Post Harvest' in a.value:
for j in range(95, 96):
a = ws1.cell(row=i, column=j)
if 'GH Soil' in a.value:
GHSBRID.append((ws1.cell(row=i, column=1)).value)
print('GHSBRID:', GHSBRID)
elif 'Field Soil' in a.value:
FSBRID.append((ws1.cell(row=i, column=1)).value)
print('FSBRID:', FSBRID)
else:
print ('Data Not Complete')
x = datetime.datetime.now()
mydir = os.path.join('/home/elinor/Desktop', x.strftime('%Y-%m-%d%H'))
os.makedirs(mydir)
os.chdir(mydir)
for x in FSBRID:
print(x)
FSBRws2['L12'] = x
a = str(x)
FSBR.save(a + '.xlsx')
for x in FSVRID:
print(x)
FSVRws2['L12'] = x
a = str(x)
FSVR.save(a + '.xlsx')
for x in GHSBRID:
print(x)
GHSBRws2['L12'] = x
a = str(x)
GHSBR.save(a + '.xlsx')
for x in GHSVRID:
print(x)
GHSVRws2['L12'] = x
a = str(x)
GHSVR.save(a + '.xlsx')
for x in TLV:
print(x)
TLVws2['L12'] = x
a = str(x)
TLVwb.save(a + '.xlsx')
for x in TFB:
print(x)
TFBws2['L12'] = x
a = str(x)
TFBwb.save(a + '.xlsx')
Это то, что мой код возвращает / печатает значения et c:
TFB: [1]
TLV: [2]
TLV: [3]
TFB: [4]
[5]
[6]
GHSBRID: [7]
FSBRID: [8]
8