pgmendormi
pgmendormi

Reputation: 224

how write with xlsxwriter in excel in a existing file without deleting the old data

i know my question is quite strange but i have a problem,

When i try to put "toto" at line a5, it suppress all my old data. there is my code (i just followed the documentation).

import xlsxwriter
 
# Workbook() takes one, non-optional, argument
# which is the filename that we want to create.
workbook = xlsxwriter.Workbook('hello.xlsx')
 
# The workbook object is then used to add new
# worksheet via the add_worksheet() method.
worksheet = workbook.add_worksheet()
 
# Use the worksheet object to write
# data via the write() method.
worksheet.write('A4', 'Hello..')
worksheet.write('B1', 'Geeks')
worksheet.write('C1', 'For')
worksheet.write('D1', 'Geeks')
 
# Finally, close the Excel file
# via the close() method.
workbook.close()

that code functions, but i would like to add some elements after this. When i retry the function with differents values, it deletes the hello on a4 etc how can i do? Thanks for yours answer,

Upvotes: 3

Views: 6171

Answers (1)

Robxon
Robxon

Reputation: 206

XlsxWriter can only create new files. It cannot read or modify existing files. There is a module called openpyxl that allows you to read and write to preexisting excel files.

Upvotes: 7

Related Questions