tell application "Pages"
tell document 1
tell page 1
tell table 1
tell column 1
set value of cell 1 to "Hello World"
end tell
end tell
end tell
end tell
end tell
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
to getCellInTable:tblIdx onPage:targetPage atRow:rowIdx atColumn:colIdx
set cellValue to missing value
tell application "Microsoft Word"
-- figure out what page we are currently on
set rng to collapse range (text object of selection) direction collapse start
set currentPage to (get range information rng information type active end page number) as integer
-- and how many pages are in this document
set numPages to (get range information rng information type number of pages in document) as integer
-- exit if we are looking for a page beyond the end of the document
if targetPage > numPages then
error number -128
end if
tell active document
if targetPage = currentPage then
-- if the current selection is on the page we are looking for,
-- we can just grab the range of the current page
set foundPage to text object of bookmark "\\Page"
else
-- Otherwise we have to walk the pages of the document to find the one we want
-- starting from first page of document
set firstWord to word 1
if targetPage > 1 then
set foundPage to navigate firstWord to goto a page item position relative count (targetPage - 1)
else
set foundPage to navigate firstWord to goto a page item position absolute
end if
end if
(*
At this point, foundPage contains the text object of the desired page
and we can extract tables, etc.
*)
tell foundPage
set tbl to table 1
set c to get cell from table tbl row rowIdx column colIdx
-- get rid of extra \r at the end of the cell content
set rng to text object of c
set rng to move end of range rng by a character item count -1
set cellValue to content of rng
end tell
end tell
end tell
return cellValue
end getCellInTable:onPage:atRow:atColumn:
on run
set targetPage to 4
set cellVal to my getCellInTable:1 onPage:2 atRow:3 atColumn:2
end run
Edited to account for more code paths.
Note that in the event you are looking for cell data from a table on a page different than the current page, this script will move through the pages on screen and you will lose your current selection. There are ways around this if necessary.