Re: AppleWorks Spreadsheet manipulation
Re: AppleWorks Spreadsheet manipulation
- Subject: Re: AppleWorks Spreadsheet manipulation
- From: T&B <email@hidden>
- Date: Fri, 16 Feb 2001 11:24:28 +1100
How can the contents of cells in an AppleWorks spreadsheet be manipulated?
Of course I have checked the dictionary of AppleWorks,
I think that you're just not reading it correctly. The property is "spreadsheet", its class is "spreadsheet layer". The latter should not actually appear in your script.
along the lines of 'get cell 1 of spreadsheet layer of document 1' or 'formula of cell ...' or any of a zillion other similar constructs work.
According to the dictionary:
Class document: an open document
Properties:
spreadsheet spreadsheet layer [r/o] -- the document?s spreadsheet (if spreadsheet document)
which gives us the sytax: spreadsheet of document 1
and:
Class spreadsheet layer: a spreadsheet
Elements:
cell by name, by numeric index
suggests: cell 1 in spreadsheet of document 1
or: cell "A1" in spreadsheet of document 1
The properties of a cell include:
Class cell: a cell
Properties:
formula text -- the formula of the cell
Unfortunately, it does not (but should) have a "value" property to return the value in the cell. "Formula" will work, but if it is a calculation, it will return that calculation (eg "=1+1"), not the result that appears in the cell (eg "2"). You can, however, get the value by just getting the cell itself:
get cell 1 in spreadsheet of document 1
However, this fails in some circumstances (eg Mac OS X) and, since it is not a property, does not provide a "whose" clause, such as:
get every cell in spreadsheet of document 1 whose value is 2.0
The ONLY command that works for me is the simple 'paste'. Since AppleWorks is not recordable, I can't try out how it is supposed to be done, or if it is broken in some way.
You can gain a better understanding of how the dictionary structure works in this tutorial:
http://www.tandb.com.au/applescript/tutorial/
especially the chapter on "specifying an object" at:
http://www.tandb.com.au/applescript/tutorial/07/
which explains how to cross reference the class of a property.
Coincidentally, the above tutorial uses AppleWorks for its examples, but the lessons apply to all applications. For more specific AppleWorks scripting tips and sample scripts, see:
http://www.tandb.com.au/appleworks/
My real task is simply to paste a tab delimited text at the first empty row, then go and make some rows bold!
I don't know why/how it's on the cliipboard, but I suggest getting those values from your other application into a variable in your script, not copying to the clipboard. Copy and paste in AppleScript is a last resort, not because it's difficult, just not elegant and robust.
I also suspect that you would be better served by an AppleWorks database rather than a spreadsheet. If I knoew more about what you are doing, I could advise better.
Utterly simple, and therefore a bit embarrassing to ask that on this very fine mailing list, but I am completely stuck...
One method would be:
tell application "AppleWorks 6"
tell spreadsheet of front document
set columnCount to number of columns
repeat with rowN from 1 to number of rows
set rowIsEmpty to true
repeat with columnN from 1 to columnCount
if formula of cell columnN in row rowN is not "" then
set rowIsEmpty to false
exit repeat
end if
end repeat
if rowIsEmpty then exit repeat
end repeat
select cell 1 in row rowN
end tell
activate
paste
end tell
Please reply to this list, not me directly.
Thanks,
Tom
T&B