1
如何循環遍歷Excel命名的範圍/定義名稱中的單元格,並使用Python 2.7中的openpyxl設置命名範圍內的每個單元格值?使用Python中的Excel命名範圍和openpyxl
我發現了以下內容,但還沒有設法讓它在指定範圍內打印和設置單個單元格的值。
Read values from named ranges with openpyxl
這裏是我的代碼,到目前爲止,我已經把在我期待所做的更改意見。感謝預期。
#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]
你到底明白了什麼? –
提取單個單元格值,但現在我已解決它,並將發佈解決方案以防其他人遇到同樣的問題。感謝您的關注。 – Py1001