尝试编写一个Python脚本,该脚本将打开我创建的现有发票模板,并提示信息填写单元格。使用目标名称创建文件,最后的print语句成功打印用于单元格C5的值,脚本完成且没有错误。打开新创建的Excel文件时,单元格C3和C5中不会显示任何数据。最初我错过了保存声明,并认为这是我的问题,但是在添加之后我仍然遇到了同样的问题。请帮忙!
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
答案 0 :(得分:0)