Re: Numbers '08 (Selection range)
Re: Numbers '08 (Selection range)
- Subject: Re: Numbers '08 (Selection range)
- From: KOENIG Yvan <email@hidden>
- Date: Wed, 14 Jan 2009 17:02:54 +0100
Done.
Your tracking number for this issue is Bug ID# 6495420.
Hello
In the Numbers AppleScript dictionary, there is no
get selection instruction.
To grab the current selected range, with several scripters, we built
a workaround.
--\[SCRIPT getSelectedCells]{code}
(*
Thanks to Scott Lindsey & Ed.Stockly from applescript-
email@hidden
*)
set {rName, dName, sName, tName} to my getSelection()
if rName is missing value then error "No selected cells"
set twoNames to my decoupe(rName, ":")
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, _, myRange, myTable,
mySheet, myDoc, mySelection
--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 {_, myRange, _, myTable, _, mySheet, _, myDoc} to my
decoupe(errMsg, quote)
--set mySelection to (a reference to (range rn of table tn of
sheet sn))
return {myRange, myTable, mySheet, myDoc}
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}
Some questions appear:
(1) may you add a 'get selection' instruction ?
(2) when whe grab a range selection, we get:
«class C4:D8" of table "test table 2 2" of sheet "Data1" of document
"Sans titre"
which nothing can decipher a clean way.
Here, the workaround was to grab the error message generated by an
attempt to coerce this result as string.
It works but it's ugly.
(3) when the lup
repeat with sheetRanges in mySelectedRanges
returns sheetRanges for a sheet containing a single table, the result
is wrongly formed.
It is a single descriptor, not a list so, we are forced to check its
class to get a correct behavior.
I tried to use:
if the class of sheetRanges is not list then set sheetRanges to
{sheetRanges}
but it fails this way:
get class of «class C7:D11" of table "Tableau 1" of sheet "Data2" of
document "Sans titre"
"Erreur dans Numbers : Impossible de transformer class of «class of
table \"Tableau 1\" of sheet \"Data2\" of document \"Sans titre\" en
type reference."
so, I uses the ugly:
try
count of sheetRanges
on error
set sheetRanges to {sheetRanges}
end try
I hope that you will be able to repair that.
Yvan KOENIG (from FRANCE mercredi 14 janvier 2009 17:02:50)
_______________________________________________
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