0

I am trying to write a string to a certain cell in an Excel file by Python. This is what I have written:

from openpyxl import Workbook
wb = Workbook()
ws = wb.active
ws.cell(row =1, column=2).value = t1

However, the following error appears:

TypeError: Value must be a list, tuple, range or generator, or a dict. Supplied value is <class 'str'>

How can I write a string to cell?

1
  • could you tell what's t1 in code? Commented Feb 26, 2021 at 18:10

1 Answer 1

1

Is this what you are looking to accomplish ?

from openpyxl import Workbook
wb = Workbook()
ws = wb.active
t1='asd'
ws.cell(row =1, column=2,value = t1)
wb.save("fileName.xls")

enter image description here this save a file with value asd in the cell

Sign up to request clarification or add additional context in comments.

1 Comment

This does indeed answer the question.

Your Answer

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