Attemping to write a Python script that will open an existing invoice template I have created and prompt for the info to fill in the cells. The file is created with the intended name, the print statement at the end successfully prints the value intended for cell C5, and the script finishes without errors. Upon opening the newly created Excel file, no data appears in cells C3 and C5. Initially I was missing the save statement and assumed that was my problem, however after adding it I'm still running into the same issue. Please help!
import openpyxl
#prompt for invoice number
invNumber = raw_input('What is this invoice number? ')
#convert string to integer
invNumberInt = int(invNumber)
file ='test.xlsx'
wb = openpyxl.load_workbook(file)
ws = wb.get_sheet_by_name('Sheet1')
ws['C3'] = invNumberInt
#invoice due date
dueDate = raw_input('When is this invoice due? mm/dd/yyyy: ')
ws['C5'] = dueDate
wb.save(filename = "invoice%d.xlsx" % invNumberInt)
print ws['C5'].value
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.