Python Forum
Problem writing a variable value to Excel - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Problem writing a variable value to Excel (/thread-20035.html)



Problem writing a variable value to Excel - Chuck_Norwich - Jul-24-2019

Hi,

creating an invoice program to write to Excel. Want to take the invoice number in C36, add 1 and write to C36 again and save so that next time I run the program same thing happens but 1 higher.

Code below will get value of C36 and add 1 - am proving this by print, won't be in final code, just to see what is happening.

But, have played around with various lines of code to take the actual number value of new_invoice_number and save to C36

Have left in my failed commented out code for moment so can see what has been tried

Where am I going wrong? Or have I just made it too complicated?

from openpyxl import load_workbook

wb = load_workbook(r'C:\Users\Ron McMillan\OneDrive\RMES invoice\RMES_invoice.xlsx')

sh = wb.active

invoice_number = sh ['C36']

print (invoice_number.value)

#sh['C36'] = '=Sum(C36+1)'

#sh [C36].value = sh [C36].value + 1

new_invoice_number = invoice_number.value + 1

print(new_invoice_number)

#sheet.cell(row=3, column=36).value = new_invoice_number

#sh.cell[C36].value = new_invoice_number

#sh.cell (C36).value = new_invoice_number
Thanks


RE: Problem writing a variable value to Excel - Chuck_Norwich - Jul-25-2019

Figured it.