我有一个擅长:
-blank-
aaaa
1
2
3
-blank-
bbbb
1
2
3
我正在尝试:
1)检查单元格是否有值
2)如果它没有值,则将第二个单元格值(例如aaaa)(直到下一个空白单元格出现)写入B列,但我认为我离结果太远了< / p>
所以结果将是:
column A column B
-blank- aaaa
aaaa aaaa
1 aaaa
2 aaaa
3 aaaa
-blank- bbbb
bbbb bbbb
1 bbbb
2 bbbb
3 bbbb
代码:
import openpyxl
wb=openpyxl.load_workbook('deneme.xlsx')
sheet=wb.active
cell_range1 = sheet['A1':'A8']
a=sheet['A']
b=sheet['B']
for row in cell_range1:
for cell in row:
value = cell.value
if value is None:
for i in range(???):
new_value=sheet.cell( row=(i+1), column=1 ).value
print( new_value )
for index in range( 1, ??? ):
for cell in b:
b[index].value=new_value
print (b[i])
else:
print ("I dont know what to do")
wb.save( 'sonuc1.xlsx' )