[英]Accessing the cell objects value openpyxl at row level
我想為電子表格第一列的每一行中的值創建一個 hash 鍵,然后將行值的 rest 加載到字典中(認為這是正確的 Z23EEEB4347BDD26BFC6B7EE9A3B755)訪問行和單元格的值。
我搜索了各種示例和教程,我已經接近我想要的,但似乎我無法訪問創建哈希鍵所需的數據。 我得到錯誤:
hashString = row.cell(row=baseincr,column=1)
AttributeError: 'tuple' object has no attribute 'cell'
我無法訪問正確的 object,但不知道我應該使用哪種類型的 object。 我嘗試使用“.active”使用整個工作表來獲取整個工作表,但這也失敗並出現同樣的錯誤。
totalcols = tuple(sheet['A12':'J100'])
baseincr = 0
hashString = ""
dataHash = {hashString:[]}
for row in totalcols:
baseincr += 1
hashString = row.cell(row=baseincr,column=1)
for cell in row:
dataHash.setdefault(hashString,[]).append(cell.value)
好的,我找到了解決方案。
for row in totalcols:
baseincr += 1
hashString = sheet.cell(row=baseincr,column=1).value
for cell in row:
dataHash.setdefault(hashString,[]).append(cell.value)
您可以通過給出行和列直接訪問單元格中的值,但它是工作表的屬性,而不是元組或行。
好的,我找到了解決方案。
for row in totalcols:
baseincr += 1
hashString = sheet.cell(row=baseincr,column=1).value
for cell in row:
dataHash.setdefault(hashString,[]).append(cell.value)
您可以通過給出行和列直接訪問單元格中的值,但它是工作表的屬性,而不是元組或行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.