I am newbie and i will appreciate some help for my code.I have wrote that function:
def write_captions_to_excel_file(self, filenames, titles, indexs, description_path):
print('writing to excel')
workbook = Workbook(os.path.join(description_path, 'all_captions.xlsx'))
worksheet = workbook.add_worksheet()
firstrow = 0
worksheet.write(firstrow, 0, 'Image name') # 3 --> row number, column number, value
worksheet.write(firstrow, 1, 'Titles')
worksheet.write(firstrow, 2, 'Description')
row = indexs + 1
worksheet.write(row, 0, filenames)
origin_title = titles.h1.getText()
worksheet.write(row, 1, origin_title.capitalize())
print(origin_title.capitalize())
worksheet.write(row, 2, '')
sleep(3)
workbook.close()
The problem is that i call that function many times, first time gives me the result in row 0 and 1, then when it runs again it gives me the results in row 0 and row 2, row 1 results have been erased. Same in other's calls.
I think that every time i call the function it creates from the beginning the workbook and i lost the previous data.How can avoid that?
As i see in the documentation XlsxWriter is designed only as a file writer. It cannot read or modify an existing Excel file.
Thank you