• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Scripting Numbers a Little More – Extracting Data into an Array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting Numbers a Little More – Extracting Data into an Array


  • Subject: Re: Scripting Numbers a Little More – Extracting Data into an Array
  • From: Yvan KOENIG <email@hidden>
  • Date: Tue, 07 Feb 2017 16:27:47 +0100


Le 7 févr. 2017 à 03:59, Christopher Stone <email@hidden> a écrit :

Hey Folks,

Okay, this is what I'm fooling with at the moment, and it's working well enough.

( Although if anyone has some good tips I'm all eyes and ears. :)

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/02/06 17:01
# dMod: 2017/02/06 19:42 
# Appl: Numbers
# Task: Extract Formatted Data from Cells.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Numbers, @Extract, @Formatted, @Data, @Cells
# Vers: 1.00
-------------------------------------------------------------------------------------------

tell application "Numbers"
   if document 1 exists then
      tell document 1
         tell active sheet
            
            try
               set activeTable to (the first table whose class of selection range is range)
            on error
               error "Something is wrong with the selection in the front document."
            end try
            
            tell activeTable
               set rowList to rows of selection range
               repeat with theRow in rowList
                  set contents of theRow to formatted value of cells of theRow
               end repeat
            end tell
            
         end tell
      end tell
   end if
end tell

repeat with theRow in rowList
   repeat with theCell in theRow
      if (contents of theCell) is missing value then
         set contents of theCell to ""
      end if
   end repeat
end repeat

rowList

-------------------------------------------------------------------------------------------

If you don't iterate through the rows and just get the value of the cells of the selection, you end up with a flat list (which will work fine for some tasks of course).

--
Best Regards,
Chris

Loops are required to replace missing value by "" but they aren't to extract the content of the cells in an array.

tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
tell selection range
set theValues to value of cells of rows
set theFormattedValues to formatted value of cells of rows
end tell
end tell

Both instructions return a list of lists.
CAUTION: although we are telling to selection range which may restricted to some columns, the instructions return the value of every cells of every selected rows.

Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) mardi 7 février 2017 16:27:26



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Scripting Numbers a Little More – Extracting Data into an Array
      • From: Christopher Stone <email@hidden>
References: 
 >Scripting Numbers a Little More – Extracting Data into an Array (From: Christopher Stone <email@hidden>)

  • Prev by Date: InDesign problems placing items on spreads
  • Next by Date: Re: InDesign problems placing items on spreads
  • Previous by thread: Scripting Numbers a Little More – Extracting Data into an Array
  • Next by thread: Re: Scripting Numbers a Little More – Extracting Data into an Array
  • Index(es):
    • Date
    • Thread