Exporting single sheet to .csv

I'm adding links to a Numbers spreadsheet via a .csv conversion process (lots of links). Problem is that I haven't found a way to convert one sheet of a multi-sheet file to .csv. Conversion from Numbers seems to be all or nothing, which is a pain if there are multiple sheets in the file. Each sheet consists of one table, if that makes any difference. Workaround is to create a separate file for each sheet and convert that file to .csv, but that's cumbersome IF there's an easier way to accomplish the task. Any ideas? Thanks!


Posted on Oct 30, 2023 8:30 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 30, 2023 11:32 AM

There is no way within Numbers, it's all or nothing as you found out.


If it's something you'll do often you might want to use Applescript with these instructions.


And here's the script to do it. Open the Numbers document to the correct sheet before running the script.


set {ATID_run, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}

tell application "Numbers"
	tell active sheet of front document
		set fileName to name
		
		tell table 1
			set aText to {}
			
			repeat with aRow in rows
				set aLine to {}
				
				repeat with aCell in aRow's cells
					if value of aCell is not missing value then
						-- quotes added in case the cell value includes the text separator itself
						set end of aLine to "\"" & formatted value of aCell & "\""
						-- or
						-- set end of aLine to value of "\"" & value of aCell & "\""
					else
						set end of aLine to ""
					end if
				end repeat
				set end of aText to aLine
			end repeat
			
		end tell
	end tell
end tell

tell application "TextEdit"
	activate
	set aCSVDocument to make new document at the front with properties {name:fileName}
	repeat with aLine in aText
		make new paragraph at after last paragraph of text of aCSVDocument with data (aLine as string) & return
	end repeat
end tell
-- the document needs to be manually saved

set AppleScript's text item delimiters to ATID_run

4 replies
Question marked as Top-ranking reply

Oct 30, 2023 11:32 AM in response to yugojnab

There is no way within Numbers, it's all or nothing as you found out.


If it's something you'll do often you might want to use Applescript with these instructions.


And here's the script to do it. Open the Numbers document to the correct sheet before running the script.


set {ATID_run, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}

tell application "Numbers"
	tell active sheet of front document
		set fileName to name
		
		tell table 1
			set aText to {}
			
			repeat with aRow in rows
				set aLine to {}
				
				repeat with aCell in aRow's cells
					if value of aCell is not missing value then
						-- quotes added in case the cell value includes the text separator itself
						set end of aLine to "\"" & formatted value of aCell & "\""
						-- or
						-- set end of aLine to value of "\"" & value of aCell & "\""
					else
						set end of aLine to ""
					end if
				end repeat
				set end of aText to aLine
			end repeat
			
		end tell
	end tell
end tell

tell application "TextEdit"
	activate
	set aCSVDocument to make new document at the front with properties {name:fileName}
	repeat with aLine in aText
		make new paragraph at after last paragraph of text of aCSVDocument with data (aLine as string) & return
	end repeat
end tell
-- the document needs to be manually saved

set AppleScript's text item delimiters to ATID_run

Oct 30, 2023 11:48 AM in response to yugojnab

I cannot say for the other spreadsheets.


In each category of software (spreadsheet, word processors, image editors, etc.) each application has its own unique features and omit some that exist in other similar products which we wish were included.


If you need to suggest something to Apple use this link, although I'm pretty sure the single-sheet export in Numbers has already been requested many times.

Product Feedback - Apple


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.

Exporting single sheet to .csv

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