compare two documents

Hello


I am using Numbers 09.


I have 2 Numbers documents and what I would like to do is compare the same column in both documents for unique information. If one of the documents has unique information I have to add it to my master document, one of the two documents.


The idea behind automating this is to remove a mundane task currently done by hand.


My goal is to find a way of automating the task of finding unique numbers for one specfic column that both documents share.


Any insight?


Thanks for considering.


Regards

Posted on Apr 19, 2012 3:24 AM

Reply
6 replies

Apr 19, 2012 4:45 AM in response to LostAccount

LA,


Let's say your data column is A, just for the purpose of giving you an example solution. In each document, add a new column to the right of column A.


Further, we'll say that the tables involved are T1 and T2 and that these columns have 1 Header Row.


In B2 of T1 write: =COUNTIF(T2 :: A, A) and Fill Down to the end of the data area.


In B2 of T2 write: =COUNTIF(T1:: A, A) and Fill Down to the end of the data area.


You will get a result such as this:


User uploaded file

Wherever you see a count greater than zero in column B, the data in column A appears in the other table as well.


The formula will survive a sort, so you can collect the duplicates/uniques by sorting the result column. Here's an example where values duplicated are sorted thte top, leaving unique values at the bottom.


User uploaded file


Regards,


Jerry


Note: An earlier post contained a mistake and was replaced by this one during the edit window. j.

Apr 20, 2012 4:58 AM in response to Jerrold Green1

Your answer is really helpful and that's what I call thinking out of the box (the part of copying the column from one doc to another)


But, there is always a but, it's not possible then to compare two worksheets in two different documents and highlight the one sheet’s differences for one particular column against the column in a different document then is there?


Can't atomator help with this? Apple claims that Numbers is not automator ready but when launching automator I can't find Numbers as a target to choose from.


If the only recourse is to follow Jerold's advice then it's a workaround.


I sincerely appreciate the great solutions posed here. I will wait for any further remarks and mark the answers given as helpful or otherwise.


Thank you so much!

Alex

Apr 20, 2012 5:05 AM in response to Jerrold Green1

I just wanted to add some further information about my particular need and I appreciate that you are all trying to help me.


The two documents (we'll call them tables because we know that we can add more than one table to one Numbers document) have over twenty colums but it is only one column that I am interested in comparing and highlighting differences from.


OK thanks again.

Apr 20, 2012 2:05 PM in response to LostAccount

Really easy to achieve with a script.


--{code}

--[SCRIPT compare 2 columns from 2 Numbers docs]

(*

Enregistrer le script en tant que Script : compare 2 columns from 2 Numbers docs.scpt

déplacer le fichier ainsi créé dans le dossier

<VolumeDeDémarrage>:Utilisateurs:<votreCompte>:Bibliothèque:Scripts:Applications :Numbers:

Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.


Ouvrir les deux documents à comparer.

Ici on suppose que l'on doit comparer le contenu des colonnes 2 de la 1ère table de la 1ère feuille des documents.

Aller au menu Scripts , choisir Numbers puis choisir “compare 2 columns from 2 Numbers docs”

Le script crée un fichier text et l'ouvre avec Numbers.


--=====


L’aide du Finder explique:

L’Utilitaire AppleScript permet d’activer le Menu des scripts :

Ouvrez l’Utilitaire AppleScript situé dans le dossier Applications/AppleScript.

Cochez la case “Afficher le menu des scripts dans la barre de menus”.

Sous 10.6.x,

aller dans le panneau “Général” du dialogue Préférences de l’Éditeur Applescript

puis cocher la case “Afficher le menu des scripts dans la barre des menus”.


--=====


Save the script as a Script: compare 2 columns from 2 Numbers docs.scpt


Move the newly created file into the folder:

<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:

Maybe you would have to create the folder Numbers and even the folder Applications by yourself.


Open the two spreadsheets to compare.

Here we assume that we must compare column 2 of table 1 of sheet 1 of both documents.


Go to the Scripts Menu, choose Numbers, then choose “compare 2 columns from 2 Numbers docs”

The script create a temp text file and open it with Numbers.


--=====


The Finder’s Help explains:

To make the Script menu appear:

Open the AppleScript utility located in Applications/AppleScript.

Select the “Show Script Menu in menu bar” checkbox.

Under 10.6.x,

go to the General panel of AppleScript Editor’s Preferences dialog box

and check the “Show Script menu in menu bar” option.


--=====


Yvan KOENIG (VALLAURIS, France)

2012/04/20

*)

--=====

on run

local liste1, liste2, liste3, IF_loc, delim_loc, the_formula, r, tempDoc, nomHaut, nomBas


my activateGUIscripting()


tell application "Numbers"


(*

Extract values from the column to compare.

*)

tell document 1 to tell sheet 1 to tell table 1

set liste1 to value of cells of column 2

end tell


(*

Extract values from the column to compare.

*)

tell document 2 to tell sheet 1 to tell table 1

set liste2 to value of cells of column 2

end tell

end tell


(*

Normalize the lists lengths

*)

if (count liste1) > (count liste2) then

repeat

set end of liste2 to ""

if (count liste2) = (count liste1) then exit repeat

end repeat

else if (count liste1) < (count liste2) then

repeat

set end of liste1 to ""

if (count liste2) = (count liste1) then exit repeat

end repeat

end if


(*

Build a list of couples (val from doc1) tab (val from doc 2)

*)

set liste3 to {}

repeat with r from 1 to count liste1

set end of liste3 to ((item r of liste1) as text) & tab & item r of liste2

end repeat


(*

Build the path to a temporary text file

*)

set tempDoc to ((path to temporary items as text) & "compare.txt")


(*

Write the values to compare in the text file

*)

my writeTo(tempDoc, my recolle(liste3, return), text, false)


(*

Build the comparison formula

*)

set IF_loc to my getLocalizedTabularString("Numbers", "IF")

set delim_loc to my getLocalizedDelimiter()

set the_formula to "=" & IF_loc & "(A=B" & delim_loc & quote & quote & delim_loc & quote & "different" & quote & ")"

tell application "Numbers"


(*

Open the text file

*)


opentempDoc

tell document 1 to tell sheet 1 to tell table 1

(*

Add a new column

*)


add column after last column

set nomHaut to name of first cell of last column

set nomBas to name of last cell

(*

Fill the first cell of the new column

*)

set value of cellnomHaut to the_formula

set selection range to range (nomHaut & " : " & nomBas)

end tell

end tell


(*

Fill the entire column

*)

my selectSubMenu("Numbers", 5, 10, 2) -- Fill Down

end run


--=====

(*

Handler borrowed to Regulus6633 - http://macscripter.net/viewtopic.php?id=36861

*)

on writeTo(targetFile, theData, dataType, apendData)


-- targetFile is the path to the file you want to write


-- theData is the data you want in the file.


-- dataType is the data type of theData and it can be text, list, record etc.


-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it

try

set targetFile to targetFile as text

set openFile to open for accessfiletargetFile with write permission

if not apendData then set eof of openFile to 0


writetheDatatoopenFilestarting ateofasdataType


close accessopenFile

return true

on error

try


close accessfiletargetFile

end try

return false

end try

end writeTo


--=====


on decoupe(t, d)

local oTIDs, l

set oTIDs to AppleScript's text item delimiters

set AppleScript's text item delimiters to d

set l to text items of t

set AppleScript's text item delimiters to oTIDs

return l

end decoupe


--=====


on recolle(l, d)

local oTIDs, t

set oTIDs to AppleScript's text item delimiters

set AppleScript's text item delimiters to d

set t to "" & l

set AppleScript's text item delimiters to oTIDs

return t

end recolle


--=====

(*

Set the parameter delimiter which must be used in Numbers formulas

*)

on getLocalizedDelimiter()

if character 2 of (0.5 as text) is "." then

return ","

else

return ";"

end if

end getLocalizedDelimiter


--=====


on get_iWorkNum(a)

local verNum

tell application a to set verNum to item 1 of my decoupe(get version, ".")

if (a is "Numbers" and verNum is "2") or (a is "Pages" and verNum is "4") then

return "09"

else

return "11"

end if

end get_iWorkNum


--=====


on getLocalizedName(a, x, f)

tell application a to return localized string x from table "Localizable" in bundle file f

end getLocalizedName


--=====

(*

Useful to get function’s localized name if we need to build formulas

examples:

set OFFSET_loc to my getLocalizedTabularString("Numbers", "OFFSET")

set ADDRESS_loc to my getLocalizedTabularString("Numbers", "ADDRESS")

set INDIRECT_loc to my getLocalizedTabularString("Numbers", "INDIRECT")

set Unnamed_Table_loc to my getLocalizedTabularString("Numbers", "Unnamed Table")


Requires :

decoupe()

get_iWorkNum()

getLocalizedName()

*)

on getLocalizedTabularString(theApp, x)

local path2app


activateapplicationtheApp

tell application "System Events"

set path2app to (application file of (get application process theApp) as text)

exists folder (path2app & "Contents:Frameworks:")

end tell

if result then

path2app & "Contents:Frameworks:SFTabular.framework:Versions:A:Resources:"

else

(path to application support as text) & "iWork '" & my get_iWorkNum(theApp) & ":Frameworks:SFTabular.framework:Versions:A:Resources:"

end if

return my getLocalizedName(theApp, x, result)

end getLocalizedTabularString


--=====


on activateGUIscripting()


(* to be sure than GUI scripting will be active *)

tell application "System Events"

if not (UI elements enabled) then set (UI elements enabled) to true

end tell

end activateGUIscripting


--=====

(*

my selectSubMenu("Pages",6, 4, 26)

==== Uses GUIscripting ====

*)

on selectSubMenu(theApp, mt, mi, ms)



activateapplicationtheApp

tell application "System Events" to tell application process theApp to tell menu bar 1 to ¬

tell menu bar item mt to tell menu 1 to tell menu item mi to tell menu 1 to click menu item ms

end selectSubMenu


--=====

--[/SCRIPT]

--{code}


Yvan KOENIG (VALLAURIS, France) vendredi 20 avril 2012

iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.3

My Box account is : http://www.box.com/s/00qnssoyeq2xvc22ra4k

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.

compare two documents

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