Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 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 Answer

0 votes
by (71.8m points)

Did you import the load_workbook function, like this?

from openpyxl import load_workbook

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...