Monday, May 25, 2020

#1 Yesterday 10:18:06 am

wayland
Member
Registered: 2020-05-13
Posts: 4

Use AppleScript to search a Numbers document for a string

I'm wondering if it's possible to search a Numbers document for a string, let's say, "hello" and then have it return the cell identifier for where that string exists. For example, if "hello" is in cell C2 in a numbers document, the script would return C2 when it finds the string "hello" in it.

Offline

 

#2 Yesterday 10:49:06 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4344

Re: Use AppleScript to search a Numbers document for a string

Applescript:

tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
   set theValues to value of every cell
   set theKey to "hello"
   set found to "key unavailable"
   set nbColumns to count columns
   set indx to 0
   repeat with r from 1 to count rows
       repeat with c from 1 to nbColumns
           set indx to indx + 1
           if item indx of theValues = theKey then
               set found to (name of cell r of column c)
               exit repeat
           end if
       end repeat
   end repeat
end tell
found

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 mai 2020 18:48:58

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)