Python Forum
Problem writing a variable value to Excel
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem writing a variable value to Excel
#1
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
Reply
#2
Figured it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with writing monitored data to mysql upon change of one particular variable donottrackmymetadata 3 279 Apr-18-2024, 09:55 PM
Last Post: deanhystad
  dynamic variable name declaration in OOP style project problem jacksfrustration 3 789 Oct-22-2023, 10:05 PM
Last Post: deanhystad
  Function parameter not writing to variable Karp 5 948 Aug-07-2023, 05:58 PM
Last Post: Karp
  Excel file reading problem max70990 1 899 Dec-11-2022, 07:00 PM
Last Post: deanhystad
Bug Writing in a document problem IOHANNES 4 1,059 Oct-26-2022, 08:58 PM
Last Post: IOHANNES
  Need Help writing data into Excel format ajitnayak87 8 2,523 Feb-04-2022, 03:00 AM
Last Post: Jeff_t
  problem writing dataframe to oracle aliyesami 4 2,661 Sep-25-2021, 11:20 PM
Last Post: SamHobbs
  Problem in saving .xlsm (excel) file using pandas dataframe in python shantanu97 2 4,305 Aug-29-2021, 12:39 PM
Last Post: snippsat
  Using Excel Cell As A Variable In A Loop knight2000 7 4,126 Aug-25-2021, 12:43 PM
Last Post: snippsat
  Using Excel Cell As A Variable In A Loop knight2000 7 5,030 Jul-18-2021, 10:52 AM
Last Post: knight2000

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020