4 Replies Latest reply on Nov 10, 2014 12:46 AM by VeluVK

    Remove spaces from the empty cells

    VeluVK

      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

        • 1. Re: Remove spaces from the empty cells
          Jump_Over Level 5

          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

          • 2. Re: Remove spaces from the empty cells
            Sajeev Sridharan Level 4

            Try this,

             

            for (s=0; s<app.activeDocument.stories.length; s++)
            {
                for (t=0; t<app.activeDocument.stories[s].tables.length; t++)
                {
                    app.activeDocument.stories[s].tables[t].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[i].cells
                            for(var j=0;j<cell.length;j++)  
                            {  
                                if(cell[j].contents == " " || cell[j].contents == " ") //add your conditions here like double spaces, double non breaking space etc..
                                {  
                                    cell[j].select();
                                    cell[j].texts[0].remove();
                                }
                            }
                        }
                    }
                }
            }
            

             

             

            Vandy

            • 3. Re: Remove spaces from the empty cells
              pixxxel schubser Level 5

              Sajeev Sridharan,

              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[i].contents = cellTxt[i].contents.replace(/^\s+$/,'');
              } 
              
              

               

              Have fun

               

              • 4. Re: Remove spaces from the empty cells
                VeluVK Level 1

                Thaks vandy,

                 

                It working fine

                 

                Regards,

                velu

                • 5. Re: Remove spaces from the empty cells
                  VeluVK Level 1

                  Hi pixxxel schubser,

                   

                  It working fine.

                   

                   

                  Regards,

                  velu