Python - Use to tablib to import Excel (xls, xlsx) files -


i'm having trouble figuring out how import excel files python script. i'm few days python i'm guessing it's obvious i'm missing. i'm using python 3 , tablib module. examples on tablib site, i've worked out how save files in xls format

    def savexls(self, name, data):                 # form dataset accompanying headers         datatab =  tablib.dataset()         datatab.headers = data[0][:]          in range(1,len(data)):             datatab.append(data[i][:])          open(self.savedir + name + ".xls", 'wb') f:             f.write(datatab.xls)      

(i know loop horrible , un-pythonic, it's important results @ moment it's work). @ moment, open excel workbook , save text file (i should point out data tab-delimited , consists of strings, numbers).

i open this

    def loadtxt(self,name, filetype, data):             if( filetype == "txt"):                             open(self.currentworkingdir + "\\" + name + ".txt",'r') f:                     reader=csv.reader(f,delimiter='\t')                     x in reader:                         data.append(x) 

i tried copying "dbf" example on tablib website (http://tablib.readthedocs.org/en/latest/api/) get

    def loadxls(self):             self.data = tablib.dataset()             self.data = open('data.xlsx').read()             return self.datav 

and error (as expected, pulled ass)

unicodedecodeerror: 'charmap' codec can't decode byte 0x8f in position 637: character maps .

i have no clue how figure out unfortunately, advice appreciated.

you've figured out now, next person, need read excel file binary:

my_input_stream = open("my_file.xlsx", "rb") my_dataset = tablib.import_set(my_input_stream) dataset[1:5] 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -