def exportToExcel(self):
wb = openpyxl.Workbook()
columnHeaders = []
# create column header list
for j in range(self.ui.table.columnCount()):
columnHeaders.append(self.ui.table.horizontalHeaderItem(j).text())
df = pd.DataFrame(columns=columnHeaders)
print(df)
# create dataframe object recordset
for row in range(self.ui.table.rowCount()):
for col in range(self.ui.table.columnCount()):
item = self.ui.table.item(row, col)
df.at[row, columnHeaders[col]] = item.text() if item is not None else ""
df.to_csv('result.csv', index=False)
PyQt5 将QTableWidget导出为csv
最新推荐文章于 2023-10-16 11:20:24 发布