Wednesday, December 14, 2011

Making a Selection in a Table

Table selections are powerful because they make it possible to use clipboard operations on a selected table region.

Table selections must be rectangular. Table selections work off of row and column numbers rather than row objects and column numbers as you might first expect.

Row numbering is from top to bottom with the first row numbered 0.
Column numbering is from left to right with the first column numbered 0.

The following script selects the first column in the currently selected table. Note the need to count the number of rows in the table before making the selection.

function countTableRows(table) {
    var count = 0, row;
    row = table.FirstRowInTbl;
    while (row.ObjectValid()) {
        count = count + 1;
        row = row.NextRowInTbl;
    return count;

function selectLeftMostColumn(table) {
    var rowCount;
    rowCount = countTableRows(table);
    if (table.ObjectValid()) {
        table.MakeTblSelection(0, rowCount - 1, 0, 0);

var doc, table;
doc = app.ActiveDoc;
table = doc.SelectedTbl;

No comments:

Post a Comment