简体   繁体   中英

Cant save an excel file using python script

def getFile():
    global filename, path, path2

    filename = QtWidgets.QFileDialog.getOpenFileName()[0]
    path = filename

    print(path)
    

I think the problem is in this function

def getTo():
    wb = load_workbook(filename = filename)

and there is mising some settings in filename functon, i tried using unicode, but it doesnt solve the problem

Traceback (most recent call last):
  File "C:/Users/pro10/PycharmProjects/Program/gui5.py", line 118, in getTo
    sheet['A' + str(rows)] = text1
  File "C:\Users\pro10\PycharmProjects\pythonProject\venv\lib\site-packages\openpyxl\worksheet\worksheet.py", line 313, in __setitem__
    self[key].value = value
  File "C:\Users\pro10\PycharmProjects\pythonProject\venv\lib\site-packages\openpyxl\cell\cell.py", line 216, in value
    self._bind_value(value)
  File "C:\Users\pro10\PycharmProjects\pythonProject\venv\lib\site-packages\openpyxl\cell\cell.py", line 199, in _bind_value
    raise ValueError("Cannot convert {0!r} to Excel".format(value))
ValueError: Cannot convert <function text1 at 0x0000023DFE3D3A60> to Excel
 
  

Did you import the load_workbook function, like this?

from openpyxl import load_workbook

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM