从excel- openpyxl-PYTHON 3.6获取值时出错和警告

问题描述 投票:0回答:1

我正在尝试使用以下代码从单元格中获取值:

import openpyxl
wb=openpyxl.load_workbook(r'C:\Users\xyz\Desktop\xxx.xlsx')
sheet=wb.active
v = sheet.cell(9,9).value
print(v)

当我执行代码时,我收到以下错误:

Warning (from warnings module):
  File "C:\Users\XYZ\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\worksheet\worksheet.py", line 303
    warn("Using a coordinate with ws.cell is deprecated. Use ws[coordinate] instead")
UserWarning: Using a coordinate with ws.cell is deprecated. Use ws[coordinate] instead

Traceback (most recent call last):
  File "C:/Users/XYZ/Desktop/test.py", line 14, in <module>
    v = sheet.cell(9,9).value
  File "C:\Users\XYZ\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\worksheet\worksheet.py", line 304, in cell
    row, column = coordinate_to_tuple(coordinate)

  File "C:\Users\XYZ\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\utils\cell.py", line 185, in coordinate_to_tuple
    col, row = coordinate_from_string(coordinate)

  File "C:\Users\XYZ\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openpyxl\utils\cell.py", line 45, in coordinate_from_string
    match = COORD_RE.match(coord_string.upper())

AttributeError: 'int' object has no attribute 'upper'

任何人都可以说我的程序有什么问题。

python python-3.x openpyxl
1个回答
3
投票

您需要使用关键字参数:

v = sheet.cell(row=9, column=9).value
© www.soinside.com 2019 - 2024. All rights reserved.