python - write the output of a function to an Excel cell -
i'm trying write output of user defined function cell in excel
this works. writes value cell:
wb = openpyxl.load_workbook('example.xlsx') sheet = wb.get_sheet_by_name('sheet1') sheet.cell(row=(lastrow+1),column=2).value = random.randint(1,100) wb.save('example.xlsx')
but not. cell remains empty:
def reader1(): random.randint(1,100) wb = openpyxl.load_workbook('example.xlsx') sheet = wb.get_sheet_by_name('sheet1') sheet.cell(row=(lastrow+1),column=2).value = reader1() wb.save('example.xlsx')
i not receive error message in either case. i've tried various ways, cannot work. appreciated, including feedback on formatting of post (my first).
thanks
you're not returning function, need return value of random.randint
have column update it's value. default function returns none
def reader1(): return random.randint(1,100)
Comments
Post a Comment