Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python openpyxl module says: AttributeError: 'tuple' object has no attribute 'upper'

Installed Python 3.4 and modules jdcal and openpyxl:

Trying myself on the openpyxl library to read and write XLSX files from Python. I installed the jdcall module and the openpyxl module. Code lets me create the workbook and work sheet:

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

However, if I try to write to the first cell like this:

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

Python says:

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>

Any idea what I am doing wrong?

like image 487
Wolf Metzner Avatar asked Sep 23 '26 20:09

Wolf Metzner


1 Answers

Cell coordinates should be provided as a string:

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

Or, if you want to use row and column indexes, use ws.cell().value:

ws.cell(row=1, column=1).value = 'testing 1-2-3'
like image 73
alecxe Avatar answered Sep 26 '26 09:09

alecxe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!