Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

openpyxl - 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:Userspro10PycharmProjectspythonProjectvenvlibsite-packagesopenpyxlworksheetworksheet.py", line 313, in __setitem__
    self[key].value = value
  File "C:Userspro10PycharmProjectspythonProjectvenvlibsite-packagesopenpyxlcellcell.py", line 216, in value
    self._bind_value(value)
  File "C:Userspro10PycharmProjectspythonProjectvenvlibsite-packagesopenpyxlcellcell.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
 
  
question from:https://stackoverflow.com/questions/65913049/cant-save-an-excel-file-using-python-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Did you import the load_workbook function, like this?

from openpyxl import load_workbook

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...