我无法将数据从qtablewidget保存到excel
def save(self):
path = QtWidgets.QFileDialog.getSaveFileName(self.tableWidget_2,'Save File', '', 'CSV(*.csv)')
#if not path.isEmpty():
with open(str(path), 'wb') as stream:
writer = csv.writer(stream)
for row in range(self.tableWidget_2.rowCount()):
rowdata = []
for column in range(self.tableWidget_2.columnCount()):
item = self.tableWidget_2.item(row, column)
if item is not None:
rowdata.append(str(item.text()).encode('utf8'))
else:
rowdata.append('')
writer.writerow(rowdata)
我收到此追溯错误:
回溯(最近通话最近):
保存时保存文件“ C:\ Users \ Warren \ Desktop \ new interface \ code \ create_summary.py”,行60 使用open(str(path),'wb')作为流:
OSError:[Errno 22]无效的参数:“('C:/ Users / Warren / Desktop / new interface / code / dsdsd.csv','CSV(*。csv)')”
该如何解决?
答案 0 :(得分:0)
只需解压缩getSaveFilename
中的结果:
path, _ = QtWidgets.QFileDialog.getSaveFileName(self.tableWidget_2,'Save File', '', 'CSV(*.csv)')