Re: Numbers '08 (Selection range)
Re: Numbers '08 (Selection range)
- Subject: Re: Numbers '08 (Selection range)
- From: KOENIG Yvan <email@hidden>
- Date: Tue, 13 Jan 2009 13:39:48 +0100
And here is the complete code:
--\[SCRIPT getSelectedCells]{code}
(*
Thanks to Scott Lindsey & Ed.Stockly from applescript-
email@hidden
*)
set {rangeName, dName, sName, tName} to my getSelection()
if rangeName is missing value then error "No selected cells"
set twoNames to my decoupe(rangeName, ":")
set {colNum1, rowNum1} to my decipher(item 1 of twoNames)
if item 2 of twoNames = item 1 of twoNames then
set {colNum2, rowNum2} to {colNum1, rowNum1}
else
set {colNum2, rowNum2} to my decipher(item 2 of twoNames)
end if
display dialog "first cell : column " & colNum1 & " of row " &
rowNum1 & return & "last cell : column " & colNum2 & " of row " &
rowNum2 & return & "of table " & tName & return & "of sheet " & sName
& return & "of document " & dName
--=====
on getSelection()
local mySelectedRanges, sheetRanges, thisRange, _, rn, tn, sn, dn, sln
--tell application "Macintosh HD:Applications:iWork '09:Numbers.app"
tell application "Numbers"
tell document 1
set mySelectedRanges to selection range of every table of every
sheet whose it is not missing value
repeat with sheetRanges in mySelectedRanges
try
count of sheetRanges
on error
set sheetRanges to {sheetRanges}
end try
repeat with thisRange in sheetRanges
if contents of thisRange is not missing value then
try
--return thisRange --poorly formed result
thisRange as text
on error errMsg number errNum
set {_, rn, _, tn, _, sn, _, dn} to my decoupe(errMsg, quote)
--set sln to (a reference to (range rn of table tn of sheet sn))
return {rn, tn, sn, dn}
end try
end if -- contents…
end repeat -- thisRange
end repeat -- sheetRanges
end tell -- document 1
end tell -- application
return {missing value, missing value, missing value, missing value}
end getSelection
--=====
on decipher(n)
local colNum, rowNum, letters
set letters to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
if (character 2 of n) as text > "9" then
set colNum to (offset of (character 1 of n) in letters) * 64 +
(offset of (character 2 of n) in letters)
set rowNum to (text 3 thru -1 of n) as integer
else
set colNum to offset of (character 1 of n) in letters
set rowNum to (text 2 thru -1 of n) as integer
end if
return {colNum, rowNum}
end decipher
--=====
on decoupe(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return l
end decoupe
--=====
--[/SCRIPT]{code}
Yvan KOENIG (from FRANCE mardi 13 janvier 2009 13:36:35) _______________________________________________
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