简体   繁体   中英

openpyxl - get input from QLineEdit and save in excel

I want to use openpyxl to get the user input from a QLineEdit and save it to an Excel file. The script below works well when no QLineEdit is envolved but is not working under openpyxl. The error message I get is: cannot convert QlineEdit to Excel.

self.le.setText(str(text))
text = self.le.text()
wb = load_workbook (source_file)
ws = wb.active
ws.append ([text])
wb.save (source_file)

What would be a way to this? C

Any help would be appreciated. Thanks in advance.

Its possible that with more code I could provide a more certain answer, but QT has several problems with typing in python. More specifically it returns 'Qtypes' for a lot of common python types that need to be manually converted before they can be serialized. Try this:

self.le.setText(str(text))
text = str(self.le.text())
wb = load_workbook (source_file)
ws = wb.active
ws.append ([text])
wb.save (source_file)

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