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

finding cell overflow in table - problem with script

Explorer ,
Oct 15, 2015 Oct 15, 2015

Copy link to clipboard

Copied

Hello,

as a translation company, we often do some DTP on translated Framemaker documents. The documents often contain many tables, and the translated text doesn't always fit into the cells, giving overflow. I'm looking into creating a script that finds the overflow in the table cells.

I've already tested some scripts, and have now run into an issue I can't seem to work out. I started out by detecting the overflowed cells in a selected table, which works fine, and gives an alerts when overflow is detected. This script:

// == WORKS ON SELECTED TABLE ==

var doc = app.ActiveDoc; 

var tbl = doc.SelectedTbl; 

var row = tbl.FirstRowInTbl; 

var cell; 

 

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

    cell = row.FirstCellInRow; 

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

     if (cell.Overflowed === 1) { 

  alert("cell overflow Will Robinson!");

  }

        cell = cell.NextCellInRow; 

    } 

    row = row.NextRowInTbl; 

// == END OF WORKS ON SELECTED TABLE ==

However, I thought it would be nice to loop through the tables in a document, and find all overflowed cells, instead of going table by table. So this script successfully loops through tables, rows and cells in a document:

// === LOOPS THROUGH TABLE, NO OVERFLOW ===

var doc = app.ActiveDoc;

var tbl = app.ActiveDoc.FirstTblInDoc;

var row = tbl.FirstRowInTbl;

var cell;

while (tbl.ObjectValid()) {

  alert ("gimme a table");

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

  cell = row.FirstCellInRow; 

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

  alert("gimme a cell");

  cell = cell.NextCellInRow;

  }

  row = row.NextRowInTbl;

  }

tbl = tbl.NextTblInDoc; 

}   

// === END OF LOOPS THROUGH TABLE, NO OVERFLOW ===

When I add the block

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

     if (cell.Overflowed === 1) { 

  alert("cell overflow Will Robinson!");

into this script, it doesn't work. It appears the cell.OverFlowed needs the table to be selected? Does anyone know how to get around this -by either selecting the table if the object is valid before looping through the rows, or by detecting the cell.OverFlowed in the above script?

I also -because why not:) - tried running the overflowed on the doc.flow instead of FirstTbl, but although it detects flowes/frames and subcol correctly, it still doesn't register the overflow.

var doc = app.ActiveDoc

var flow = doc.FirstFlowInDoc

var frame = flow.FirstTextFrameInFlow

var subcol =frame.FirstSubCol

while (flow.ObjectValid()){       

            while (frame.ObjectValid()) {              

                    while (subcol.ObjectValid()){

                        if (subcol.OverFlowed === 1){

                        alert("colsies"); //doesn't work!

                        }

                        subcol = subcol.NextSubCol

                        }

                frame = frame.NextTextFrameInFlow

                }

            flow = flow.NextFlowInDoc

   }

I'm clearly missing something, but I can't seem to figure out what? Any help would be greatly appreciated...

Kind regards,

Geert

TOPICS
Scripting

Views

763

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 , Oct 15, 2015 Oct 15, 2015

Your code in the second script is not quite right. Try this:

var doc, tbl, row, cell;

doc = app.ActiveDoc;

tbl = doc.FirstTblInDoc;

while (tbl.ObjectValid ()) {

    row = tbl.FirstRowInTbl;

    while (row.ObjectValid ()) {

        cell = row.FirstCellInRow;

        while (cell.ObjectValid ()) {

            if (cell.Overflowed === 1) {

                alert ("Cell overflowed");

            }

            cell = cell.NextCellInRow;

        }

        row = row.NextRowInTbl;

    }

    tbl = tbl.Next

...

Votes

Translate

Translate
Community Expert ,
Oct 15, 2015 Oct 15, 2015

Copy link to clipboard

Copied

Your code in the second script is not quite right. Try this:

var doc, tbl, row, cell;

doc = app.ActiveDoc;

tbl = doc.FirstTblInDoc;

while (tbl.ObjectValid ()) {

    row = tbl.FirstRowInTbl;

    while (row.ObjectValid ()) {

        cell = row.FirstCellInRow;

        while (cell.ObjectValid ()) {

            if (cell.Overflowed === 1) {

                alert ("Cell overflowed");

            }

            cell = cell.NextCellInRow;

        }

        row = row.NextRowInTbl;

    }

    tbl = tbl.NextTblInDoc;

}

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
Explorer ,
Oct 15, 2015 Oct 15, 2015

Copy link to clipboard

Copied

Hello,

super, this works like a charm! Thanks for the quick assistance

Just for clarity, the problem was due to the fact that I declare my row variable at the start instead of after checking if the table object is valid? (which in retrospect would make sense...)

Kind regards,

Geert

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
Mentor ,
Oct 15, 2015 Oct 15, 2015

Copy link to clipboard

Copied

Hi Geert, indeed Rick got the answer. I replied to your cross-post on the other forum but I failed to see the issue. Thanks Rick. Yes, your original script just keeps going over the same row in the same table, because you never reset row to the new table under scrutiny.

Russ

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
Explorer ,
Oct 15, 2015 Oct 15, 2015

Copy link to clipboard

Copied

Hello Russ,

I was just typing a reply in the other post to let you know Rick got it indeed. Thanks to both of you for the quick replies!

Rick, I marked your answer as the correct one.

Kind regards,

Geert

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 ,
Oct 15, 2015 Oct 15, 2015

Copy link to clipboard

Copied

I am trying to catch up to Russ as far as points, but by that time I will be answering from the nursing home.

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
Explorer ,
Jul 16, 2020 Jul 16, 2020

Copy link to clipboard

Copied

Hello, is there a way for the script to take it to the page or CELL where the overflow takes place?

 

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
Explorer ,
Jul 23, 2020 Jul 23, 2020

Copy link to clipboard

Copied

LATEST

Suryanarayanan_21,

If you create a TextRange using the first paragraph in the cell, you can then use the CenterOnText method on the containing doc.

 

var firstPara = targetCell.FirstPgf;
var selection = new TextRange(new TextLoc(firstPara, 0), new TextLoc(firstPara, 0));

currentDoc.CenterOnText(selection);

 

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