当我尝试将我的表(QTableWidget)保存为csv文件时,所有内容都适合excel文件中的第一个单元格,我如何分隔每个单元格?这是我的保存功能:
def save_text(self, table):
path = QFileDialog.getSaveFileName(self, 'Save CSV', os.getenv('HOME'), 'CSV(*.csv)')
if path[0] != '':
with open(path[0], 'w') as csv_file:
writer = csv.writer(csv_file, dialect='excel')
for row in range(table.rowCount()):
row_data = []
for column in range(table.columnCount()):
item = table.item(row, column)
if item is not None:
row_data.append(item.text())
else:
row_data.append('')
writer.writerow(row_data)
答案 0 :(得分:0)
尝试更换:
writer = csv.writer (csv_file, dialect = 'excel')
在
writer = csv.writer (csv_file, dialect = 'excel', delimiter = ';')