2017-07-07 50 views
0

我是编程新手。 我正在学习用python语言编写。我目前正试图将现有的字典放入一个新的excel文件中。我有一种感觉,因为我有一本字典可能是问题? 我使用的是openpyxl。openpyxl的问题:试图将字典插入新的excel文件

每当我尝试插入字典时,都会收到一条错误消息(AttributeError:'WriteOnlyWorksheet'对象没有属性'单元格')。不过,我可以写一个没有问题的简单单元格。 这是当试图填充大量数据到列中,我得到的错误。

#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') 
+0

我没有,我会看看! 编辑:对象没有属性写入 :P –

回答

0

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().

这就是为什么错误告诉你,没有属性细胞因此使用append()代替。

您也可以参考此topic以获得更多帮助和理解。

希望这有帮助。

+1

非常感谢你!这对我很有帮助 –

+0

完全没问题,希望我可以帮助更多@JulianSilvestri –