excel - Python script to convert xls to csv with non-ascii -


i have script see below works fine when xls contains ascii data. i've tried adding utf-8 @ various points script still falls on when xls contain non-ascii.

#!/usr/bin/env python  import xlrd import csv  book = xlrd.open_workbook('/users/admin/documents/pythonscripts/an_excel_file.xls')  # assuming fist sheet of interest  sheet = book.sheet_by_index(0)  # many options here control how quotes handled, etc. csvwriter = csv.writer(open('/users/admin/documents/pythonscripts/a_csv_file.csv', 'w'), delimiter=',')   in range(sheet.nrows):     csvwriter.writerow(sheet.row_values(i)) 

any ideas how add in?

this how solve problem utf-8 data. hope helps

your_csv_file = open('myfile.csv'), 'wb') wr = csv.writer(your_csv_file, quoting=csv.quote_all) rownum in xrange(worksheet.nrows):     wr.writerow([unicode(entry).encode("utf-8") entry in worksheet.row_values(rownum)]) your_csv_file.close() 

you can prefer source code given here: http://www.phuctrancs.info/file_server/convertxls.zip


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -