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:

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

Leave a Reply

Your email address will not be published. Required fields are marked *