If you open the CSV file in notepad or some other basic text editor you will see that the data is saved with spaces in between each row of data. Because EXCEL reads a CSV per new line then it will always import this way into EXCEL.
Only things you can really do is manually going in and removing the lines from the CSV, building a macro to clean it up for you after the fact or editing the tkintertable
library where the issue is occurring.
The Usage page of the GitHub for tkintertable
does not appear to have any details on exporting to CSV that will fix this issue. Just a problem with how this library works with data I guess.
Even adding a Button that runs a command to export you get the same problem.
def export_to_csv():
table.exportTable()
Button(root, text='test CSV', command=export_to_csv).pack()
Usage

UPDATE:
After doing some digging and realizing the tkintertable
uses the csv
librarty to write to csv I did some googling on the same problem with writing to csv using the csv
library and found this post (csv.write skipping lines when writing to csv). With that post I did some digging in the tkintertable
library to find where the writing occurred and here is what I found.
The writing of new lines in between data appears to be a result of how the csv
library is writing data. If we dig in you will find that the tkintertable
class that is writing your table to CSV is called ExportTableData
. That class is as follows:
class TableExporter:
def __init__(self):
"""Provides export utility methods for the Table and Table Model classes"""
return
def ExportTableData(self, table, sep=None):
"""Export table data to a comma separated file"""
parent=table.parentframe
filename = filedialog.asksaveasfilename(parent=parent,defaultextension='.csv',
filetypes=[("CSV files","*.csv")] )
if not filename:
return
if sep == None:
sep = ','
writer = csv.writer(open(filename, "w"), delimiter=sep)
model=table.getModel()
recs = model.getAllCells()
#take column labels as field names
colnames = model.columnNames
collabels = model.columnlabels
row=[]
for c in colnames:
row.append(collabels[c])
writer.writerow(row)
for row in recs.keys():
print(row)
writer.writerow(recs[row])
return
If we update this line:
writer = csv.writer(open(filename, "w"), delimiter=sep)
To include lineterminator = '\n'
you will find that the problem goes away:
writer = csv.writer(open(filename, "w"), delimiter=sep, lineterminator = '\n')
Results:

Keep in mind editing libraries is probably not a great idea but for this situation I think it is your only option.
To get to this class you will need to open the python file called Tables_IO.py
in the tkintertable
library.
If you are using PyCharm you can navigate through the library files with CTRL+Left Click.
First Ctrl+Click on the import name
. Then you will Ctrl+Click on the import name
. Then you will search for a class method called exportTable
and inside that method you will Ctrl+Click
. This will take you to the above mentioned class that you can edit to solve the problem.
Please take care not to edit anything else as you can very easily break your library and will need to reinstall it if that happens.