我有这个代码:
for row in ws.iter_rows('A1:C2'):
for cell in row:
print cell
我想打印出单元格的实际值,换句话说,该单元格的实际内容是什么。我知道这很容易,但我在任何地方都找不到它。我尝试做ws[cell],但它带来了一个错误。
以下是现在给出的内容:
<openpyxl.cell.read_only.ReadOnlyCell object at 0x0296EFC0>
<openpyxl.cell.read_only.ReadOnlyCell object at 0x0295F6F0>
<openpyxl.cell.read_only.ReadOnlyCell object at 0x0295F6F0>
<openpyxl.cell.read_only.ReadOnlyCell object at 0x0297E5D0>
<openpyxl.cell.read_only.ReadOnlyCell object at 0x0297E5A0>
<openpyxl.cell.read_only.ReadOnlyCell object at 0x0295F6F0>
要获取openpyxl
单元格的值,您需要使用 cell.value
方法。
在您的代码中:
for row in ws.iter_rows('A1:C2'):
for cell in row:
print cell.value