Automator XLSX to CSV
Hi,
Is there any way to use automator to convert .XSLX files to .CSV?
Thanks.
iMac 21.5″ 4K, macOS 12.4
Hi,
Is there any way to use automator to convert .XSLX files to .CSV?
Thanks.
iMac 21.5″ 4K, macOS 12.4
The script looks functional, but there are some simple syntax errors (typos, missing spaces, etc.).
Here's a cleaned up version. Try this:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
--begin script
--check for an output folder and create it if necessary:
set docs_folder to (path to downloads folder)
set conversion_folder to (docs_folder as text) & "Converted Excel files"
tell application "Finder" to if not (exists folder conversion_folder) then ¬
make new folder at docs_folder with properties {name:"Converted Excel files"}
--ask user to choose Excel files (.xlsx or xls):
set file_list to (choose file of type {"org.openxmlformats.spreadsheetml.sheet", ¬
"com.microsoft.Excel.xls"} with multiple selections allowed)
--process each file in turn by opening in Numbers, exporting as csv to the ouput folder, then closing the original
repeat with each_file in the file_list
tell application "Numbers"
activate
open each_file
repeat while not (exists document 1) -- wait for Excel file to open in Numbers
end repeat
set file_name to name of document 1
export document 1 to file (conversion_folder & ":" & file_name & ".csv") as CSV
close document 1 without saving
end tell
end repeat
The script looks functional, but there are some simple syntax errors (typos, missing spaces, etc.).
Here's a cleaned up version. Try this:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
--begin script
--check for an output folder and create it if necessary:
set docs_folder to (path to downloads folder)
set conversion_folder to (docs_folder as text) & "Converted Excel files"
tell application "Finder" to if not (exists folder conversion_folder) then ¬
make new folder at docs_folder with properties {name:"Converted Excel files"}
--ask user to choose Excel files (.xlsx or xls):
set file_list to (choose file of type {"org.openxmlformats.spreadsheetml.sheet", ¬
"com.microsoft.Excel.xls"} with multiple selections allowed)
--process each file in turn by opening in Numbers, exporting as csv to the ouput folder, then closing the original
repeat with each_file in the file_list
tell application "Numbers"
activate
open each_file
repeat while not (exists document 1) -- wait for Excel file to open in Numbers
end repeat
set file_name to name of document 1
export document 1 to file (conversion_folder & ":" & file_name & ".csv") as CSV
close document 1 without saving
end tell
end repeat
You can try to install gnumeric via homebrew (install gnumeric) and then set an automator action with the following command:
ssconvert Excel.xls CSV.csv
Where Excel.xls is the input file and CSV.csv is the output (converted) file.
Another option is to use LibreOffice with the following command:
/Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to csv Excel.xls
So I found this code in the thread:
--begin script
--check for an output folder and create it if necessary:
set docs_folder to path to dowloads folder
set conversion_folder to (docs_folder as string) & "Converted Excel files"
tell application "Finder" to if not (exists folder conversion_folder) then ¬
make new folder at docs_folder with properties {name:"Converted Excel files"}
--ask user to choose Excel files (.xlsx or xls):
set file_list to (choose file of type {"org.openxmlformats.spreadsheetml.sheet", ¬
"com.microsoft.Excel.xls"} with multiple selections allowed)
--process each file in turn by opening in Numbers, exporting as csv to the ouput folder, then closing the original
repeat with each_file in the file_list
tell application "Numbers"
activate
openeach_file
repeat while not (existsdocument 1) -- wait for Excel file to open in Numbers
end repeat
set file_name to name of document 1
export document 1 to file (conversion_folder & ":" & file_name & ".csv") as CSV
closedocument 1 without saving
end tell
end repeat
--end script
However it is giving a syntax error when I click the hammer
Thanks! When I run the script it opens finder but I does not take the .xslx files automatic.
What I would love to achieve is:
When a xls file is downloaded (so in downloads) I want it to automatically convert it to a csv file (in the downloads folder).
Is there any way to achieve this?
I have numbers installed, so I don't see why I should install a different program.
Also I do not know where to uses these commands? I was hoping to use the steps in automator.
Automator XLSX to CSV