Greetings!
A user will supply a .xls or .csv file (with location/directory) as a system argument. If it is a CSV file, the script moves on. If it is a XLS/XLSX file, the script should save it as a CSV file. I wrote the below code, which works, but in actuality it doesn't save the CSV file properly as a CSV file, if you know what I mean. I looked on MSDN site and found some guidance -- line 12 below should be something like
xlApp.ActiveWor kbook.SaveAs(cs vOutFile, xlApp.XlFileFor mat.xlCSV)
... but that isn't working for me (AttributeError : Excel.Applicati on.XlFileFormat ).
Can someone help me with this?
Thanks!
A user will supply a .xls or .csv file (with location/directory) as a system argument. If it is a CSV file, the script moves on. If it is a XLS/XLSX file, the script should save it as a CSV file. I wrote the below code, which works, but in actuality it doesn't save the CSV file properly as a CSV file, if you know what I mean. I looked on MSDN site and found some guidance -- line 12 below should be something like
xlApp.ActiveWor kbook.SaveAs(cs vOutFile, xlApp.XlFileFor mat.xlCSV)
... but that isn't working for me (AttributeError : Excel.Applicati on.XlFileFormat ).
Can someone help me with this?
Thanks!
Code:
inFile = sys.argv[1] print inFile whereDot = inFile.find('.') print whereDot end = inFile[whereDot:] if end <> ".csv": csvOutFile = inFile[0:whereDot] + ".csv" print "xls to csv" xlApp = win32com.client.Dispatch("Excel.Application") xlApp.Visible = 0 xlApp.Workbooks.Open(inFile) xlApp.ActiveWorkbook.SaveAs(csvOutFile) xlApp.Quit() else: print "csv already exists, ok" csvOutFile = inFile
Comment