AppleScript to convert Excel files to CSV
On occasion, I need to convert Excel files to CSV for parsing by other programs. A little Googling turned up a script from Jason Garber posted here. I'm including it here because it's (1) short, and (2) I had to tweak it a tiny bit for Excel 2008:
# Convert Excel files to CSV.
# Original from http://jasongarber.com/articles/2007/06/23/convert-excel-to-csv/
# Minor modification for Excel 2008 dictionary to use "CSV file format" instead
# of "CSV" in the save command.
set theFolder to choose folder with prompt "Choose the folder that contains your Excel files"
tell application "Finder" to set theFiles to (files of theFolder)
set fileCount to count theFiles
repeat with i from 1 to fileCount
set fName to text 1 thru -5 of ((name of item i of theFiles) as text)
if ((name of item i of theFiles) as text) ends with ".xls" then
set tName to (theFolder as text) & fName & ".csv"
tell application "Microsoft Excel"
activate
open (item i of theFiles) as text
save fName in tName as CSV file format
close active workbook without saving
end tell
end if
end repeat
Thanks, Jason!