How do I loop through the cells in an Excel named range/defined name and set each cell value within the named range using openpyxl with Python 2.7?
I found the following, but have not managed to get it to work for printing and setting the values of individual cells within the named range.
Read values from named ranges with openpyxl
Here's my code so far, I have put in comments where I am looking to make the changes. Thanks in anticipation.
#accessing a named range called 'metrics'
namedRange = loadedIndividualFile.defined_names['metrics']
#obtaining a generator of (worksheet title, cell range) tuples
generator = namedRange.destinations
#looping through the generator and getting worksheet title, cell range
cells = []
for worksheetTitle, cellRange in generator:
individualWorksheet = loadedIndividualFile[worksheetTitle]
#==============================
#How do I set cell values here?
# I am looking to print and change each cell value within the defined name range
#==============================
print cellRange
print worksheetTitle
#theWorksheet = workbook[worksheetTitle]
#cell = theWorksheet[cellRange]