python - 用于 cell.value 和 cell.internal_value 的 Openpyxl 错误:“int”对象没有属性“internal_value”
问题描述
我正在尝试使用在 excel 中打印单元格的值openpyxl
。但是,我收到以下错误:当我尝试做时对象没有属性,当我尝试做'int'
时对象没有属性。'internal_value'
print(cell.internal_value)
'int'
'value'
print(cell.value)
我做了以下事情:
for cell in range(2,18):
print(int(cell.value))
print(cell.internal_value)
print(cell.value)
有任何想法吗?
解决方案
您正在循环范围,因此cell
实际上是一个整数而不是工作表的单元格,这就是您无法使用上述属性的原因。
您应该首先尝试创建一个新的电子表格或加载一个现有的电子表格,然后访问其单元格。
from openpyxl import load_workbook
wb = load_workbook(filename = 'name_of_your_spreadsheet.xlsx')
# Let's say you want to print the A column
for cell in wb['A2 A18']:
print(int(cell.value)) #this might not work
print(cell.internal_value)
print(cell.value)
如果你想range
在任何情况下使用你可以做这样的事情
from openpyxl import load_workbook
wb = load_workbook(filename = 'name_of_your_spreadsheet.xlsx')
# Let's say you want to print the A column
for i in range(2,18):
cell = ws3.cell(column=0, row=i)
print(int(cell.value)) #this might not work
print(cell.internal_value)
print(cell.value)
推荐阅读
- c++ - OPENCV:查找线方向/角度
- machine-learning - 回归问题,使用 L1、L2 和 R2 时如何解释基线结果
- types - 输入函数式编程 (OCaml)
- npm - 即使在 npm init 之后,npm 也会全局安装包
- python-3.x - numpy 数组列表而不是一个热向量
- html - css动画无法在导航栏中实现
- mysql - 初始化mysql centos 6时遇到问题
- react-native - jest / react-native:替换/禁用 Linking.catch
- php - 使用ajax插入查询不工作
- swift - mouseMoved 在 NSTrackingArea 之外触发