Skip to navigation
Get 2 columns from xlsx or csv with tk dialog
18.04.14
def get_2columns(self): ftypes = [('Excel 2007', '.xlsx'),('CSV', '.csv')] name = askopenfilename(title='Select List of Styles',initialdir=(os.path.expanduser('~/Desktop')),filetypes=ftypes) styles = [] if(name.endswith('.xlsx')): r = [] wb = xlrd.open_workbook(str(name)) sh = wb.sheet_by_index(0) for i in range(sh.nrows): val = sh.row_values(i) if(val[1] and val[1] != 'Style'): styles.append([str(val[0]).strip(),str(val[1]).strip()]) return styles elif(name.endswith('.csv')): with open(name, 'rb') as csvfile: spamreader = csv.reader(csvfile) for i in spamreader: if(len(i)>1): if(i[1] and i[1] != 'Style'): styles.append([str(i[0]).strip(),str(i[1]).strip()]) return styles else: return False
Reply
Anonymous
Information Epoch 1736564703
Don't do anything the computer can do for you.
Home
Notebook
Contact us