Using the Word Dictionary
27
Working with tables
This topic includes examples related to the following tasks:
·
Inserting text into a table cell
·
Creating a table, inserting text, and applying formatting
·
Returning text from a table cell without returning the end-of-cell marker
·
Converting existing text to a table
·
Returning the contents of each table cell
Inserting text into a table cell
The following example inserts text into the first cell of the first table in the active document. The get
cell from table command returns a single cell object.
if (count of tables of active document) 1 then
set content of text object of (get cell from table table 1 of active ¬
document row 1 column 1) to "Cell 1, 1"
end if
Creating a table, inserting text, and applying formatting
The following example inserts a four-column, three-row table at the beginning of the document. The
Repeat With...In structure is used to step through each cell in the table. Within the Repeat With...In
structure, the insert command is used to add text to the table cells (Cell 1, Cell 2, and so on).
set oDoc to active document
set oTable to make new table at oDoc with properties ¬
{text object:(create range oDoc start 0 end 0), number of rows:3, ¬
number of columns:4}
set iCount to 1
repeat with oCell in (get cells of text object of oTable)
insert text ("Cell " & iCount) at text object of oCell
set iCount to iCount + 1
end repeat
auto format table oTable table format table format colorful2 ¬
with apply borders, apply font and apply color