1

Is there a way to convert multiple files? Can I use glob.glob?

import sys

sys.path.insert(0,'D:/apera/Python27/xlrd-0.9.3')

import xlrd

import csv

ExcelFile = "D:/apera/Workspace/Sounding/sounding010.xls"
CSVFile = "D:/apera/Workspace/Sounding/sounding010.csv"

def Convert(ExcelFile, SheetName, CSVFile):
    wb = xlrd.open_workbook(ExcelFile)
    ws = wb.sheet_by_name(SheetName)
    csvfile = open(CSVFile, 'wb')
    wr = csv.writer(csvfile, quoting=csv.QUOTE_ALL, delimiter=';')

    for rownum in xrange(ws.nrows):
         wr.writerow(
         list(x.encode('latin1')
              for x in ws.row_values(rownum)))

    csvfile.close()

Convert(ExcelFile, "INPUT", CSVFile)

1 Answer 1

1

Yes, glob combined with os will work

import os
import glob

os.chdir("yourfolder")
for f in glob.glob("*.xls"):
    #call your conversion function
Sign up to request clarification or add additional context in comments.

1 Comment

can you tell me more specific? because it give me error. because the csv files need to make it multiple. i need your help. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.