gpt4 book ai didi

Python openpyxl 模块说 : AttributeError: 'tuple' object has no attribute 'upper'

转载 作者:行者123 更新时间:2023-12-01 22:32:26 25 4
gpt4 key购买 nike

安装了 Python 3.4 和模块 jdcalopenpyxl:

尝试使用 openpyxl 库从 Python 读取和写入 XLSX 文件。我安装了 jdcall 模块和 openpyxl 模块。代码让我创建工作簿和工作表:

from openpyxl import Workbook
wb = Workbook()
ws = wb.active

但是,如果我尝试像这样写入第一个单元格:

ws[ 1, 1]   = 'testing 1-2-3'

Python 说:

C:\Wolf\Python Studies>database.py
Traceback (most recent call last):
File "C:\Wolf\Python Studies\database.py", line 13, in <module>
ws[ 1, 1] = 'testing 1-2-3'
File "C:\Python34\lib\site-packages\openpyxl-2.2.0b1-py3.4.egg\openpyxl\worksheet\worksheet.py", line 403, in __setitem__
self[key].value = value
File "C:\Python34\lib\site-packages\openpyxl-2.2.0b1-py3.4.egg\openpyxl\worksheet\worksheet.py", line 400, in __getitem__ <BR>
return self._get_cell(key)
File "C:\Python34\lib\site-packages\openpyxl-2.2.0b1-py3.4.egg\openpyxl\worksheet\worksheet.py", line 368, in _get_cell
coordinate = coordinate.upper()
AttributeError: 'tuple' object has no attribute 'upper'

C:\Wolf\Python Studies>

知道我做错了什么吗?

最佳答案

单元格坐标应作为字符串提供:

ws['A1'] = 'testing 1-2-3'

或者,如果您想使用行和列索引,请使用 ws.cell().value:

ws.cell(row=1, column=1).value = 'testing 1-2-3'

关于Python openpyxl 模块说 : AttributeError: 'tuple' object has no attribute 'upper' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28973755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com