5 Replies Latest reply on Jul 28, 2014 4:59 AM by Teetan VK

    Remove space in cells.

    Dapeamel

      Hello guys,

       

       

      i got this problem.

      when we recieve indd files from our customers,

      there are sometimes a space first in each cell then comes a number in tables and sometimes there are no space.

       

      see examples below.

       

      " 2133"

      "2344"

       

      " 123"

      "123"

       

      I need to remove the space

       

      could someone help me to write a function that loops through all tables and check cells if there are a space in the cell

       

      Thank you in advance

        • 1. Re: Remove space in cells.
          Chinnadk Level 4

          Try this,

           

          var doc = app.activeDocument,  
            _tables = doc.stories.everyItem().tables.everyItem().getElements();
          app.findTextPreferences = app.changeTextPreferences = null;  
          for(var i=0;i<_tables.length;i++)
          {
                  app.findTextPreferences.findWhat = " ";
                  app.changeTextPreferences.changeTo="";
                  _tables[i].changeText();
              }
          app.findTextPreferences = app.changeTextPreferences = null;
          

           

          Regards,

          Chinna

          • 2. Re: Remove space in cells.
            Dapeamel Level 1

            Thank you Chinnadk

             

            works like a charm

            • 3. Re: Remove space in cells.
              Jump_Over Level 5

              Hi,

               

              ...don't you need spaces in headers, like "Totalsummary"?

              ...don't you use "spaced" format for numbers, like "1 232.56"?

               

              if no then yes.

               

              Jarek

              • 4. Re: Remove space in cells.
                Dapeamel Level 1

                this function is good,

                I guess I wasn't clear enough in the explaination tho..

                I gonna use grep instead,

                cause this function removes all spaces.

                so grep and a regex

                • 5. Re: Remove space in cells.
                  Teetan VK Level 1

                  Hi,

                   

                  Chinna

                   

                  I suggest find grep instead of find text

                   

                  var doc = app.activeDocument,   

                    _tables = doc.stories.everyItem().tables.everyItem().getElements(); 

                  app.findGrepPreferences = app.changeGrepPreferences = null;   

                   

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

                          app.findGrepPreferences.findWhat = "^ +"; 

                          app.changeGrepPreferences.changeTo=""; 

                          _tables[i].changeGrep(); 

                      } 

                   

                  app.findGrepPreferences = app.changeGrepPreferences = null; 

                   

                  so I think it will be a little better

                   

                  VK