Skip to content

Instantly share code, notes, and snippets.

@allanbatista
Last active July 16, 2019 21:02
Show Gist options
  • Save allanbatista/9743aef18c4b059fb2d344b7fe1d732e to your computer and use it in GitHub Desktop.
Save allanbatista/9743aef18c4b059fb2d344b7fe1d732e to your computer and use it in GitHub Desktop.
Converte arquivos XLSX para CSV em um diretório
import xlrd
import csv
import glob, os
for file in glob.glob("*.xlsx"):
print("{} start".format(file))
wb = xlrd.open_workbook(file)
sh = wb.sheet_by_name('Plan1')
with open("{}.csv".format(file.split(".")[0]), 'w+') as f:
wr = csv.writer(f, quoting=csv.QUOTE_ALL)
count = 0
for rownum in range(sh.nrows):
wr.writerow(sh.row_values(rownum))
count += 1
sys.stdout.write("%s %s%%\r" % (file, count))
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment