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

Table Column is Empty

Community Expert ,
Apr 14, 2010 Apr 14, 2010

Hi All,

I have a table where I am trying to see if a particular column is empty, meaning the it does contain any text or anchored frames. I am thinking the best approach is to check each cell in the column, but if there is a shorthand way of doing it, I would appreciate any pointers. Thank you very much.

Rick

TOPICS
Scripting
493
Translate
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 ,
Apr 14, 2010 Apr 14, 2010

What do you consider 'empty'?

alert (app.selection[0].parent.columns[0].contents.join('').length);

(this is supposed to return '0' for an empty column, some other positive value otherwise). This will not work with columns that only seem to be empty (i.e., containing a single space). And sometimes the cells are empty but their shading indicates data.

Translate
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 ,
Apr 14, 2010 Apr 14, 2010

This works fine for a column that contains more than one cell, but the join method fails for a single-cell column. This appears to be a good workaround.

<pre>

function colOrRowIsEmpty(colOrRow) {
   
    if (colOrRow.cells.length == 1) {
        if (colOrRow.contents.length == 0) {
            return true;
        } else {
            return false;
        }
    } else {
        if (colOrRow.contents.join("").length == 0) {
            return true;
        } else {
            return false;
        }
    }
}

</pre>

Thank you very much for the generous help.

Rick

Translate
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 ,
Apr 14, 2010 Apr 14, 2010
LATEST

The one thing I did not try -- but your solution seems perfect. And it's a function, returning a boolean! Well done!

Translate
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