我的Python代码应该生成一个连续的序列号。在执行原始输入并将其保存在Excel中的新行之后。但我有一个问题: 当我运行程序时,它总是覆盖最后一次运行。 那么我如何打开(读取)现有的Excel表格,在现有数据下面写入新数据而不覆盖?
我的代码是这样的:
import xlsxwriter
workbook = xlsxwriter.Workbook('file.xlsx')
worksheet = workbook.add_worksheet()
row_count = 0
col = 0
n1 = 99
n2 = 99
n3 = 99
value_manufacturer = "0"
while True:
inp = raw_input('Choose the system:')
if inp == '1':
print 'HS25 is selcted'
serial_no_HS25 = "23"
break
while True:
inp = raw_input('Is the system OK?')
if inp == '4':
n1 += 1
print (serial_no_HS25 + value_manufacturer + str(n1))
row_count += 1
if (n1) <= 999:
worksheet.write(row_count, col, serial_no_HS25 + value_manufacturer + str(n1))
worksheet.write('C3', row_count)
else:
worksheet.write(row_count, col, (n1)
else:
print ('Wrong input for HS25')
代码有效,但如何插入任何内存功能或类似的东西? 谢谢你的帮助!!!