Using the Word Dictionary
28
Returning text from a table cell without returning the end-of-cell marker
The following examples return and display the contents of each cell in the first row of the first
document table.
set oTable to table 1 of active document
repeat with aCell in (get cells of row 1 of oTable)
set myRange to create range active document start (start of content of ¬
text object of aCell) end ((end of content of text object ¬
of aCell) - 1)
display dialog (get content of myRange)
end repeat
set oTable to table 1 of active document
repeat with aCell in (get cells of row 1 of oTable)
set myRange to text object of aCell
set myRange to move end of range myRange by a character item count - 1
display dialog (get content of myRange)
end repeat
Converting existing text to a table
The following example inserts tab-delimited text at the beginning of the active document and then
converts the text to a table.
set oRange1 to create range active document start 0 end 0
set content of oRange1 to "one" & tab & "two" & tab & "three" & tab
set oRange1 to change end of range oRange1 by a paragraph item ¬
extend type by selecting
set oTable1 to convert to table oRange1 separator separate by tabs ¬
number of rows 1 number of columns 3
Returning the contents of each table cell
The following example defines a list containing the contents of the cells in the first document table.
The Repeat With...In structure is used to return the contents of each table cell and assign the text to
the next list item.
if (count of tables of active document) 1 then
set oTable to table 1 of active document
set aCells to {}
repeat with oCell in (get cells of text object of oTable)
set myRange to text object of oCell
set myRange to move end of range myRange by a character item count -1
set end of aCells to content of myRange
end repeat
end if