openpyxl - 从QLineEdit获取输入并保存在excel中

时间:2016-08-15 16:40:38

标签: python openpyxl

我想使用openpyxl从QLineEdit获取用户输入并将其保存到Excel文件中。如果没有包含QLineEdit但在openpyxl下无法正常工作,则下面的脚本运行良好。我得到的错误消息是:无法将QlineEdit转换为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)

这会是什么方式? ç

任何帮助将不胜感激。提前谢谢。

1 个答案:

答案 0 :(得分:1)

有可能通过更多代码我可以提供更确定的答案,但QT在python中输入有几个问题。更具体地说,它返回' Qtypes'对于许多常见的python类型,需要在序列化之前手动转换。试试这个:

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)