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

Remove spaces from the empty cells

Explorer ,
Nov 07, 2014 Nov 07, 2014

Hi,

In most of tables there was an empty cells. In this cells there was white spaces and non breaking spaces are occurs. I need to delete all these spaces for all tables.

Can i have any script.

Regards,

Velu

TOPICS
Scripting
809
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

correct answers 1 Correct answer

Enthusiast , Nov 07, 2014 Nov 07, 2014

Try this,

for (s=0; s<app.activeDocument.stories.length; s++)

{

    for (t=0; t<app.activeDocument.stories.tables.length; t++)

    {

        app.activeDocument.stories.tables.select();

        var sel = app.activeDocument.selection[0]; 

        if(sel instanceof Table) 

        { 

            var col = sel.columns; 

            for(var i=0;i<col.length;i++) 

            { 

                var cell = col.cells

                for(var j=0;j<cell.length;j++) 

                { 

            

...
Translate
Mentor ,
Nov 07, 2014 Nov 07, 2014

Hi,

In UI - select a table or cell range and run Grep:

find: ^\s+$

change: <empty>

script - run changeGrep() method with chosen target, i.e.

app.activeDocument.stories.everyItem().tables.everyItem().changeGrep();

Jarek

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
Enthusiast ,
Nov 07, 2014 Nov 07, 2014

Try this,

for (s=0; s<app.activeDocument.stories.length; s++)

{

    for (t=0; t<app.activeDocument.stories.tables.length; t++)

    {

        app.activeDocument.stories.tables.select();

        var sel = app.activeDocument.selection[0]; 

        if(sel instanceof Table) 

        { 

            var col = sel.columns; 

            for(var i=0;i<col.length;i++) 

            { 

                var cell = col.cells

                for(var j=0;j<cell.length;j++) 

                { 

                    if(cell.contents == " " || cell.contents == " ") //add your conditions here like double spaces, double non breaking space etc..

                    { 

                        cell.select();

                        cell.texts[0].remove();

                    }

                }

            }

        }

    }

}

Vandy

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
Explorer ,
Nov 10, 2014 Nov 10, 2014

Thaks vandy,

It working fine

Regards,

velu

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 ,
Nov 07, 2014 Nov 07, 2014

vandy88,

I'm not an InDesign scripter, but IMHO your script is too complicated.

Hi VeluVK,

I'm with Jump_Over – Grep ist a good solution.

Otherwise I think you can do something like this

// RemoveSpacesFromEmptyCells.jsx

// regards pixxxelschubser

var cellTxt = app.documents.firstItem().stories.everyItem().tables.everyItem().cells.everyItem().texts.firstItem().getElements();

for ( var i = 0; i < cellTxt.length; i++ ) {

    cellTxt.contents = cellTxt.contents.replace(/^\s+$/,'');

}

Have fun

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
Explorer ,
Nov 10, 2014 Nov 10, 2014
LATEST

Hi pixxxel schubser,

It working fine.

Regards,

velu

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