.numbers to .csv

Using Catalina on MacPro, simple conversion of a valid .numbers file to .csv

simple code ( I tried commented out lines with same error message):

tell application "Numbers"

activate

--open "/Users/joem/Desktop/playExcelNumbers.numbers"

--export "/Users/joem/Desktop/playExcelNumbers.numbers" ¬

--to file "/Users/joem/Destop/playExcelNumbers.csv" as CSV

save "/Users/joem/Desktop/playExcelNumbers.numbers" as ¬

"LSDocumentTypeCSV" in "/Users/joem/Destop/playExcelNumbers"

end tell


Error (same one if uncomment the export line and comment out the save line):

Numbers got an error: Can’t make "/Users/joem/Desktop/playExcelNumbers.numbers" into type specifier.


Anybody spot the issue? Thanks!

Posted on Mar 6, 2021 12:33 PM

Reply
Question marked as Top-ranking reply

Posted on Mar 8, 2021 11:44 AM

Thanks SG ... from the library, I found the close and quit classes, so the following code brings up the numbers sheet momentarily (i.e. a blink), and the end result is just the .csv file. ... I guess that will have to do unless someone comes up with a more "silent" solution. Speed is not an issue. (interestingly, the code from your 1st suggestion didn't work -- shown below the operational code)

tell application "Numbers". -- this works, but "blinks" the sheet on/off

set theDoc to open file "500G internal HD:Users:joem:Desktop:test.numbers"

export theDoc to file "500G internal HD:Users:joem:Desktop:test.csv" as CSV

set theDoc to close saving no

quit "Numbers"

end tell


~~~~~~~~ doesn't work ~~~~~~~~

-- gives this error: The document “test.numbers” could not be exported as “test”.

tell application "Numbers"

set theDoc to open "/Users/joem/Desktop/test.numbers"

export theDoc to "/Users/joem/Desktop/test.csv" as CSV

set theDoc to close saving no

quit "Numbers"

end tell

5 replies
Question marked as Top-ranking reply

Mar 8, 2021 11:44 AM in response to SGIII

Thanks SG ... from the library, I found the close and quit classes, so the following code brings up the numbers sheet momentarily (i.e. a blink), and the end result is just the .csv file. ... I guess that will have to do unless someone comes up with a more "silent" solution. Speed is not an issue. (interestingly, the code from your 1st suggestion didn't work -- shown below the operational code)

tell application "Numbers". -- this works, but "blinks" the sheet on/off

set theDoc to open file "500G internal HD:Users:joem:Desktop:test.numbers"

export theDoc to file "500G internal HD:Users:joem:Desktop:test.csv" as CSV

set theDoc to close saving no

quit "Numbers"

end tell


~~~~~~~~ doesn't work ~~~~~~~~

-- gives this error: The document “test.numbers” could not be exported as “test”.

tell application "Numbers"

set theDoc to open "/Users/joem/Desktop/test.numbers"

export theDoc to "/Users/joem/Desktop/test.csv" as CSV

set theDoc to close saving no

quit "Numbers"

end tell

Mar 7, 2021 7:12 AM in response to jamargevicius

You're really close!


Just need to have the script tell Numbers which doc to save


This will work:


tell application "Numbers"
	set theDoc to open "/Users/joem/Desktop/test.numbers"
	export theDoc to "/Users/joem/Desktop/test.csv" as CSV
end tell



Or, using HFS paths, where you can use things like 'path to Desktop Folder' and 'path to Documents Folder' :


tell application "Numbers"
	set theDoc to open file "Macintosh HD:Users:joem:Desktop:test.numbers"
	export theDoc to file "Macintosh HD:Users:joem:Desktop:test.csv" as CSV
end tell


SG

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

.numbers to .csv

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.