有没有办法转换多个文件?
我可以使用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)
答案 0 :(得分:1)
是的,结合os的glob将起作用
import os
import glob
os.chdir("yourfolder")
for f in glob.glob("*.xls"):
#call your conversion function