I'm working on a Python (using 2.7) project to search through excel files for a UNC path for a server that is changing, and then update the cell with the new UNC path. I'm new to python and I'm able to find the cell and print it with:
def main():
wb = load_workbook(filename = 'Book1_test.xlsx', use_iterators = True)
ws = wb.get_sheet_by_name(name = 'Sheet1')
for row in ws.iter_rows():
for cell in row:
print cell.value
But, I don't know how to update the cell with the new string, and the workbook appears to be in read only mode; probably because ws is only retrieving information.
I found lots of resources online for searching cells and printing information but not on how to update the cell after the information is found. There is a lot of information on how to create a new workbook with blanks cells, and then update your own information; also, on how to open an existing worksheet and insert contents into a new cell. I'm just not finding what I'm looking for and my skills aren't there yet to do it myself.
Here are my goals, and if someone can help I'd greatly appreciate it:
Shortcomings I'm hoping someone can help me with:
The .value property of the Cell object is settable. This means that you can do any time something like:
cell.value = 'Helloooo ladies'
If this does not work it is probably because of the optimizer read mode. Check the optimized write mode if you needed... I always found the docs of openpyxl very complete and easy to follow.
How to look for information in the cell, or recognize what you are looking for is a very open question that can be solved in thousand different ways:
But this does not have anything to do with the openpyxl framework.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With