Efficient way to merge 100 numbers documents into one

Hello all

I have about 100 documents in Numbers. They have the same dimensions (number of rows and columns and have the same headers). I would like an efficient way to merge these into one document. Is there a function or a automator script available to do this? I really don't want to cut and paste 100 documents. Thanks in advance

RezF

Posted on Jul 24, 2021 7:53 PM

Reply
Question marked as Top-ranking reply

Posted on Jul 25, 2021 8:08 AM

Here is a simple script that reads the data from the body cells of the first table on the first sheet of individual Numbers documents and places the data tab-delimited on the clipboard for pasting into a new Numbers document (or wherever).


-- read the data from the Numbers files in the folder
set theData to {} -- a list of lists to hold the data
tell application "Finder"
	set theFiles to items of (choose folder) as alias list
	repeat with aFile in theFiles
		tell application "Numbers"
			open aFile
			tell front document
				set end of theData to value of cells of rows 2 thru -1 of table 1 of sheet 1
				close
			end tell
		end tell
	end repeat
end tell

-- convert data list to tab-delimited string on clipboard for pasting
set text item delimiters to tab
set pasteStr to ""
repeat with anItem in items of theData
	repeat with aLine in items of anItem
		set pasteStr to pasteStr & aLine & return
	end repeat
end repeat
set the clipboard to pasteStr

return pasteStr -- optional -for viewing in Results panel



  1. Copy-paste script into Script Editor (in Applications > Utilities)
  2. Place all the Numbers documents in a folder
  3. Run the script
  4. Select upper-left body cell in an existing destination Numbers table and command-v or Edit > Paste and Match Style.


If "nothing happens" make sure Script Editor is listed and checked at System Preferences > Security & Privacy > Privacy > Accessibility.


SG



12 replies
Question marked as Top-ranking reply

Jul 25, 2021 8:08 AM in response to Rezf

Here is a simple script that reads the data from the body cells of the first table on the first sheet of individual Numbers documents and places the data tab-delimited on the clipboard for pasting into a new Numbers document (or wherever).


-- read the data from the Numbers files in the folder
set theData to {} -- a list of lists to hold the data
tell application "Finder"
	set theFiles to items of (choose folder) as alias list
	repeat with aFile in theFiles
		tell application "Numbers"
			open aFile
			tell front document
				set end of theData to value of cells of rows 2 thru -1 of table 1 of sheet 1
				close
			end tell
		end tell
	end repeat
end tell

-- convert data list to tab-delimited string on clipboard for pasting
set text item delimiters to tab
set pasteStr to ""
repeat with anItem in items of theData
	repeat with aLine in items of anItem
		set pasteStr to pasteStr & aLine & return
	end repeat
end repeat
set the clipboard to pasteStr

return pasteStr -- optional -for viewing in Results panel



  1. Copy-paste script into Script Editor (in Applications > Utilities)
  2. Place all the Numbers documents in a folder
  3. Run the script
  4. Select upper-left body cell in an existing destination Numbers table and command-v or Edit > Paste and Match Style.


If "nothing happens" make sure Script Editor is listed and checked at System Preferences > Security & Privacy > Privacy > Accessibility.


SG



Jul 25, 2021 5:50 AM in response to Rezf

That really depends on how your documents are structured. Documents contain sheets, tables, and other objects. You mention "number of rows and columns," which refers to tables, but give no details on where tables are located and how many are in each sheet. Screenshots might help (Shift-command-4, select the area on the screen, and release the keys. Then compose a new post in this forum and use the "mountain" Insert Image icon to upload the screenshots.)


SG

Jul 25, 2021 6:37 AM in response to Rezf

This appears to be a suitable task for AppleScript: open Numbers documents in a folder one-by-one, extract the values from the body cells of the first table on the first sheet, then insert the contents into one table on the first sheet of a new document. I'll see if I can come up with one that works. AppleScript is slow but will be better than doing this manually.


SG

Jul 25, 2021 6:15 AM in response to SGIII

Thanks again. Sorry I may not have been clear. Ideally, I would want one table in one sheet to for these documents....so it ends up looking like one long document to scroll down, and I would be able to sort columns . For example, if 100 tables each contain 6 rows and 5 columns of cell entries (I am not counting the header row which each table has but is redundant), I would like the end result to be 1 table with 600 rows, 500 column of cell entries Plus one header Row for the entries on top.

I hope this makes sense . Many thanks for your interest

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.

Efficient way to merge 100 numbers documents into one

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