excel - Python xlrd transforms integers and strings into floats -


i tried succesfully convers excel file csv converted numbers (despite fact integers or text in excel file) floats.

i know python reads default numbers floats.

is there chance turn numbers strings?

my code bellow

def excel2csv(excelfile, sheetname, csvfile):  import xlrd  import csv  workbook = xlrd.open_workbook(excelfile)  worksheet = workbook.sheet_by_name(sheetname)  csvfile = open(csvfile, 'wb')  wr = csv.writer(csvfile, delimiter=';', quoting=csv.quote_nonnumeric)   rownum in xrange(worksheet.nrows):      wr.writerow(          list(x.encode('utf-8') if type(x) == type(u'') else x               x in worksheet.row_values(rownum)))   csvfile.close() 

thank time

my work-around has been treat excel file cell-by-cell first through new nested list, , writing nested list csv file.

by accessing individual cell values, can convert them string data types leaves internals of cell as-is in csv file ( string quotation marks removed of course ).

here's how access individual cell values :

for rownum in xrange(worksheet.nrows):     col_num in xrange ( worksheet.ncols ) :         value = str ( worksheet.row (rownum ) [ column_num ].value ) 

i append these treated cell values single row , append single row nested list serves copy of original input excel file.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -