How to write/update data into cells of existing XLSX workbook using xlsxwriter in python
Quote from xlsxwriter
module documentation:
This module cannot be used to modify or write to an existing Excel XLSX file.
If you want to modify existing xlsx
workbook, consider using openpyxl module.
See also:
you can use this code to open (test.xlsx) file and modify A1 cell and then save it with a new name
import openpyxlxfile = openpyxl.load_workbook('test.xlsx')sheet = xfile.get_sheet_by_name('Sheet1')sheet['A1'] = 'hello world'xfile.save('text2.xlsx')
Note that openpyxl does not have a large toolbox for manipulating and editing images. Xlsxwriter has methods for images, but on the other hand cannot import existing worksheets...
I have found that this works for rows... I'm sure there's a way to do it for columns...
import openpyxloxl = openpyxl.load_workbook('File Loction Here')xl = oxl.['SheetName']x=0col = "A"row = xwhile (row <= 100): y = str(row) cell = col + row xl[cell] = x row = row + 1 x = x + 1