• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
May 05, 2015 May 05, 2015

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.

112111
AAAAAA
111212
AAAAAA
121111
AAAAAA
112112
AAAAAA
TOPICS
Scripting

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 05, 2015 May 05, 2015

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;

}

Votes

Translate

Translate
Community Expert ,
May 05, 2015 May 05, 2015

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 05, 2015 May 05, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 05, 2015 May 05, 2015

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 20, 2015 May 20, 2015

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 21, 2015 May 21, 2015

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 ();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2015 May 28, 2015

Copy link to clipboard

Copied

Excellent, I have this working now,

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 17, 2017 Jul 17, 2017

Copy link to clipboard

Copied

Is it possible to delete just a single cell from a table?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 18, 2017 Jul 18, 2017

Copy link to clipboard

Copied

LATEST

#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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines