Copy link to clipboard
Copied
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.
1 | 1 | 2 | 1 | 1 | 1 |
A | A | A | A | A | A |
1 | 1 | 1 | 2 | 1 | 2 |
A | A | A | A | A | A |
1 | 2 | 1 | 1 | 1 | 1 |
A | A | A | A | A | A |
1 | 1 | 2 | 1 | 1 | 2 |
A | A | A | A | A | A |
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;
}
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
Great news! Thanks Rick, I'll have a crack with this and update with any progress.
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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 ();
Copy link to clipboard
Copied
Excellent, I have this working now,
Thanks
Copy link to clipboard
Copied
Is it possible to delete just a single cell from a table?
Copy link to clipboard
Copied
#target framemaker
var doc = app.ActiveDoc;
// Get the cell object that contains the insertion point.
var pgf = doc.TextSelection.beg.obj;
var cell = pgf.InTextObj;
while (cell.LastPgf.id !== cell.FirstPgf.id) {
cell.LastPgf.Delete ();
}
cell.FirstPgf.Delete ();
You don't actually delete the cell, but you delete the paragraphs that are in the cell. If a cell only has a single paragraph in it, you only need line 11. If you think some of the cells might have multiple paragraphs, then to play it safe, use lines 8-11.