对于 Excel 使用,我想创建一个代表 A1、A2、...D1、... AB1、AB2、... 的代码
field = [A, B, C, ..., AA, AB, ..., YZ, ZZ]
data = [[1, 2,3,4,5], [2, 3,4,5,6], [3, 5,4,3,5], [4, 5,6,7,7],...] #[index, data1, data2,...]
for i in field: # A, B, C, ...
for j in range(0,10): # First index in data
for k in range(1,4):
print(str(i)+data[j][k])
我想要的结果是 A2 A3 A4 A5 B3 B4 B5 B6 C5 C4 C3 C5 ...
我想我需要使用break语句,但是我该怎么做?
如果您能教我,我将不胜感激。
for i, column in enumerate(field): # A, B, C, ...
for j in range(len(data)): # Iterate over rows in data
if j < 10: # Limit to first 10 rows if necessary
for k in range(1, 5): # Assuming you want to skip the first element in each row and limit to next 4
if i < len(data[j]) - 1: # Check if column exists in this row
print(f"{column}{j+2}: {data[j][k]}")
else:
break # Break if the column index exceeds the data row length