私は、Pythonに新たなんです。私はExcelの列に数式を挿入しようとしています。数式への入力は必ずしも1つの行から来るとは限りません。私はhave-integer-%dの形式に括弧で文字列を変換:番号が必要とされ、STRない」
formula= '=B4-(28.471-0.0146*B4+0.0008*B4^2)+D2'
formulaRegex= re.compile(r'([A-Z]+)(\d{1,})')
cellCoordinatesR= formulaRegex.findall(formula) #find a Cap. Letter and a number
rowIndex=[] #list of the row indexes i.e '4' in 'B4' and '2' in 'D2'
for group in cellCoordinatesR:
rowIndex.append(group[1])
rowIndexFormat= '('+','.join(rowIndex)+')' # add parenthesis to rowIndex list
'(4,4,4,2)'
newFormula= formulaRegex.sub(r'\1%d',formula) %rowIndexFormat
エラー:
'%d format: a number is required, not str'
私が欲しいもの:
newFormula= formulaRegex.sub(r'\1%d',formula) %(4,4,4,2)
私は現在持っているもの:
newFormula= formulaRegex.sub(r'\1%d',formula) %'(4,4,4,2)'
私はこれで方法を見つけた:
newFormula= formulaRegex.sub(r'\1%d',formula) %
(int(rowIndex[0]),int(rowIndex[1]), int(rowIndex[2]), int(rowIndex[3]))
'=B4-(28.471-0.0146*B4+0.0008*B4^2)+D2'
しかし、それは私がint(rowIndex[i])
必要な回数だけ持っていることが必要です。 %d
を何度も入力する必要がないように、どうすればいいですか?int(rowIndex[i])
何度も入力してください。
なぜ '' rowIndexプロパティ= –