Skip to main content
Known Participant
May 5, 2015
Answered

Is it possible to remove data from cells depending on the content of the neighbouring cells of a Framemaker table?

  • May 5, 2015
  • 1 reply
  • 1504 views

Is it possible to remove data from cells depending on the content of the neighbouring cells of a Framemaker table?

Below is a very basic example of the predicament I have. I have hundreds of tables that I need to edit. They contain data in rows of two as below, and are separated by a black row between each pair. The top row always has four variations but for the sake of simplicity in this example it can be either "1" or "2", 2 variations. I want to know if its possible to write a script that will allow me to remove "A" from the cells that have a "2" in the neighbouring cells (immediately above) and retain "A" in all cells with a "1" immediately above. As clear as mud right?

Any help is greatly appreciated, I'm pretty much a total newbie.

112111
AAAAAA
111212
AAAAAA
121111
AAAAAA
112112
AAAAAA
This topic has been closed for replies.
Correct answer frameexpert

From a given cell, you can also navigate to the cells above and below.

// Given the cell containing the insertion point...

var doc = app.ActiveDoc;

var pgf = doc.TextSelection.beg.obj;

var cell = pgf.InTextObj;

// ...navigate down the column.

while (cell.ObjectValid () === 1) {

  // Do something here.

  // ...

  cell = cell.CellBelowInCol;

}

// ...navigate up the column.

while (cell.ObjectValid () === 1) {

  // Do something here.

  // ...

  cell = cell.CellAboveInCol;

}

1 reply

frameexpert
Community Expert
Community Expert
May 5, 2015

Yes, this is absolutely possible and should be practical. First, you need a function to read the text in the cells. Search this forum for a function called getText; I am sure I have posted it at least once. Then you need to be able to navigate from cell-to-cell. There are several ways to do this, but here is how you can do it row-by-row. -Rick

#target framemaker

var doc = app.ActiveDoc;

// Set a variable for the table containing the insertion point.

var tbl = doc.SelectedTbl;

// Navigate row by row.

var row = tbl.FirstRowInTbl, cell;

while (row.ObjectValid () === 1) {

   cell = row.FirstCellInRow;

   while (cell.ObjectValid () === 1) {

     // Do something here.

     // ...

     cell = cell.NextCellInRow;

   }

   row = row.NextRowInTbl;

}

Known Participant
May 5, 2015

Great news! Thanks Rick, I'll have a crack with this and update with any progress.

frameexpert
Community Expert
Community Expert
May 21, 2015

Hmmmm. This deletes the first column of a table:

var doc = app.ActiveDoc;

var tbl = doc.SelectedTbl;

if(doc.ObjectValid() == true)

{         

    tbl.DeleteCols (0, 1);

}

But this doesn't delete the first row. In fact it doesn't do anything Why is this so?

var doc = app.ActiveDoc;

var tbl = doc.SelectedTbl;

if(doc.ObjectValid() == true)

{         

    tbl.DeleteRows (0, 1);

}




Cheers

Chris


The first parameter in the DeleteRows function is a Row object, not the row number. So, to delete the first row of a table containing the insertion, you should be able to do something like this.

var doc = app.ActiveDoc;

var tbl = doc.SelectedTbl;

var row = tbl.FirstRowInTbl;

tbl.DeleteRows (row, 1);

Alternatively, you can delete a single row like this:

row.Delete ();