excel – How to write/update data into cells of existing XLSX workbook using xlsxwriter in python
excel – 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:
- Modify an existing Excel file using Openpyxl in Python
- Use openpyxl to edit a Excel2007 file (.xlsx) without changing its own styles?
you can use this code to open (test.xlsx) file and modify A1 cell and then save it with a new name
import openpyxl
xfile = openpyxl.load_workbook(test.xlsx)
sheet = xfile.get_sheet_by_name(Sheet1)
sheet[A1] = hello world
xfile.save(text2.xlsx)
excel – How to write/update data into cells of existing XLSX workbook using xlsxwriter in python
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…
Im sure theres a way to do it for columns…
import openpyxl
oxl = openpyxl.load_workbook(File Loction Here)
xl = oxl.[SheetName]
x=0
col = A
row = x
while (row <= 100):
y = str(row)
cell = col + row
xl[cell] = x
row = row + 1
x = x + 1