我在使用winthon.client轉換我的.xlsx和.xls文件到.csv中。當我執行此代碼時,它提供了一個錯誤。我的代碼是:xls到csv轉換器
def convertXLS2CSV(aFile):
'''converts a MS Excel file to csv w/ the same name in the same directory'''
print "------ beginning to convert XLS to CSV ------"
try:
import win32com.client, os
from win32com.client import constants as c
excel = win32com.client.Dispatch('Excel.Application')
fileDir, fileName = os.path.split(aFile)
nameOnly = os.path.splitext(fileName)
newName = nameOnly[0] + ".csv"
outCSV = os.path.join(fileDir, newName)
workbook = excel.Workbooks.Open(aFile)
workbook.SaveAs(outCSV, c.xlCSVMSDOS) # 24 represents xlCSVMSDOS
workbook.Close(False)
excel.Quit()
del excel
print "...Converted " + nameOnly + " to CSV"
except:
print ">>>>>>> FAILED to convert " + aFile + " to CSV!"
convertXLS2CSV("G:\\hello.xlsx")
我無法在此代碼中找到該錯誤。請幫忙。
請將錯誤和全面反饋 – agf 2012-03-27 06:33:12
首先除去try/except,否則不會得到如此有用的錯誤。 – SpliFF 2012-03-27 06:34:40