function writing only last numbers exp: [-big number-, 5, 5, 5, 0.03] when it should be like this [-big number-, 1, 1, 1, 0.01]. I think its about this part workbook.save(path)
but I dont understand where I should put it.
def Calc():
global path
workbook = openpyxl.load_workbook(path)
print(workbook.get_sheet_names())
sheet = workbook.active
for i in range (0, 4):
for A in range (1, 6):
for L in range (1, 6):
for n in range (1, 6):
for T in np.arange (0.01, 0.04, 0.01):
K=A*pow((1-math.exp(-L*T)), n)
c1 = sheet.cell(row = i 10, column = 1)
c1.value=K
c2 = sheet.cell(row = i 10, column = 2)
c2.value=A
c3 = sheet.cell(row = i 10, column = 3)
c3.value=L
c4 = sheet.cell(row = i 10, column = 4)
c4.value=n
c5 = sheet.cell(row = i 10, column = 5)
c5.value=T
workbook.save(path)
#workbook.save(path)
CodePudding user response:
I change a little of your code, so it can output all rows:
from openpyxl import load_workbook
import numpy as np
import math
def Calc():
path = "./test.xlsx"
workbook = load_workbook(path)
print(workbook.get_sheet_names())
sheet = workbook.active
# NOTE: change row from 1 to 10
row = 10
for i in range (0, 4):
for A in range (1, 6):
for L in range (1, 6):
for n in range (1, 6):
for T in np.arange (0.01, 0.04, 0.01):
K=A*pow((1-math.exp(-L*T)), n)
c1 = sheet.cell(row, column = 1)
c1.value=K
c2 = sheet.cell(row, column = 2)
c2.value=A
c3 = sheet.cell(row, column = 3)
c3.value=L
c4 = sheet.cell(row, column = 4)
c4.value=n
c5 = sheet.cell(row, column = 5)
c5.value=T
row = row 1
workbook.save(path)
Calc()