0

I am new to programming. I am learning to write in the python language. I am currently trying to put an existing dictionary into a new excel file. I have a feeling that because I have a dictionary may be the issue? I am using openpyxl.

I am getting an error message(AttributeError: 'WriteOnlyWorksheet' object has no attribute 'cell' ) whenever I attempt to insert the dictionary. However I can write to a simple cell with no issue. It is when trying to fill in large data into a column that I get the error.

 #Writing a new excel file with key information
    print("Would you like to create a new excel document?")
    b_input = input("Type: 'Y' or 'N' -> ").lower()
    if b_input == "y":
        wb = Workbook(write_only=True)
        ws = wb.create_sheet()

        print("I can only put in the contract status and serial numbers together in a file.")
        c_input = input("Would you like to do that? Type: 'Y' or 'N' -> ")
        if c_input == 'y':
            ws.cell(row=r, column=1).value = excel_info


    wb.save('new_test_book.xlsx')
Julian Silvestri
  • 1,970
  • 1
  • 15
  • 33

1 Answers1

1

from the write_only mode.docs:

In a write-only workbook, rows can only be added with append(). It is not possible to write (or read) cells at arbitrary locations with cell() or iter_rows().

that's why error tells you there is no attribute cell so use append() instead.

You can also refer to this topic for more help and understanding.

Hope this was helpful.

Rayhane Mama
  • 2,374
  • 11
  • 20