I`m trying to convert .xls to .csv but when i run the code below nothing happens.
import xlrd
import csv
def csv_from_excel():
wb = xlrd.open_workbook('d://Documents and Settings//tdrub//Desktop//TreinamentoPython XLS-CSV//Teste.xls')
sh = wb.sheet_by_name('Sheet1')
Agencia = open('d://Documents and Settings//tdrub//Desktop//Agencia.csv', 'wb')
wr = csv.writer(Agencia, quoting=csv.QUOTE_ALL)
for rownum in xrange(sh.nrows):
wr.writerow(sh.row_values(rownum))
Agencia.close()
The directory is correct, the sheet name is correct but when i run the code no .csv file is created.
I appreciate if someone can help me :)
import xlrd
import csv
import os
file= open('out.csv', 'wb')
wr = csv.writer(file, quoting=csv.QUOTE_ALL)
book=xlrd.open_workbook("F.xls")
sheet=book.sheet_by_index(0)
for sheet in book.sheets():
for row in range(sheet.nrows):
wr.writerow(sheet.row_values(row))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.