3

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?

1
  • You need to specify the coordinate as a string (e.g. A1) and not as indices. Commented Mar 10, 2015 at 20:55

1 Answer 1

7

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'
Sign up to request clarification or add additional context in comments.

1 Comment

This exception is also thrown when you try to assign data to row "A0".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.