(table, sep=None)
return
Export table data to a comma separated file
Export table data to a comma separated file
Export table data to a comma separated file
def ExportTableData(table, sep=None):
        """Export table data to a comma separated file"""
        
        import platform
        
        parent=table.parentframe
        filename = filedialog.asksaveasfilename(parent=parent,defaultextension='.csv',
                                                  filetypes=[("CSV files","*.csv")] )
        if not filename:
            return
        if sep == None:
            sep = ','
        if platform.system() == "Windows":
            writer = csv.writer(open(filename, "w", newline=""), delimiter=sep)
        else: 
            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():
            writer.writerow(recs[row])
        return
def ExportTableData ( table , sep = None ) : import platform parent = table . parentframe filename = filedialog . asksaveasfilename ( parent = parent , defaultextension = '.csv' , filetypes = [ ( "CSV files" , "*.csv" ) ] ) if not filename : return if sep == None : sep = ',' if platform . system ( ) == "Windows" : writer = csv . writer ( open ( filename , "w" , newline = "" ) , delimiter = sep ) else : 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 ( ) : writer . writerow ( recs [ row ] ) return