7 Replies Latest reply on Mar 15, 2014 7:35 AM by Unique

    Go to cell and alert contents

    Unique Level 1

      Hi, I want to find and alert contens of a cell in a table. Matrix method.

      I found a stupid idea to find it.

       

      Well i could get the Number of Column and row. but i cant able to select the contents of a cell (3,1).

      (I'm trying to get alert of a content which is having header "Mate" and reference number 71247.

       

      TitleSongMateFilmTwo
      50%25050027052071247
      11%125FeckeriNJAMANRAH71248
      13222IQUEWATERWAFER71246
      UNIQUEFARESTFARTABVALUE71249

       

       

      var every = app.activeDocument.pages.everyItem(0).textFrames.everyItem().tables.everyItem().cells.eve ryItem().getElements();

      var T = [];

      var m = [];

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

      if(every[i].contents =="Mate") {

      app.findGrepPreferences.findWhat = "71247";

                app.activeDocument.findGrep(true);

                var fnd = app.activeDocument.findGrep();

            for(y=0; y<fnd.length; y++) {

                          if(fnd[y].length>0 &&

                  T.push(fnd[y].parent.name));

                  m.push(every[i].name);

                          var f= (m).join("\r").replace(":", ".");

                          var e = (T).join("\r").replace(":", ".");

                           var u = e-f;

                          var n = [];

                          n.push(u);

                   }

      }

       

      }

      alert(n);

       

       

      Many thanks for the support.

        • 1. Re: Go to cell and alert contents
          Kai Rübsamen Adobe Community Professional

          Hi,

           

          first I realize that with InDesign CC everyItem() is verry slow, even I have only two tables on one page?!

           

          Why has your last column no header "Mate"? If I understand the question correct, I would do it in this way:

           

           

          var curDoc = app.activeDocument;
          var everyHeaderRow = curDoc.pages.everyItem(0).textFrames.everyItem().tables.everyItem().rows[0].getElements();
          
          
          for( var i = 0; i<everyHeaderRow.length; i++ ) {
            var curHR = everyHeaderRow[i];
            var allHC = curHR.cells;
              
          for ( var j = 0; j < allHC.length; j++ ) {
            if ( allHC[j].contents == "Mate" ) {
              var curCol = allHC[j].columns[0];
                for ( var c = 0; c < curCol.cells.length; c++ ) {
                  var curCell = curCol.cells[c];
                    if ( curCell.contents == "71247" ) {
                      curCell.select();
                      var cellName = curCell.name;
                      var co = Number(curCell.name.split(":")[0])+1;
                      var ro = Number(curCell.name.split(":")[1])+1;
                      alert("Found\r" + "Column: " + co + "\r" + "Row: " + ro + "\r" + "Contents: " + curCell.contents);
                   }
                }
              }
            }
          }
          
          • 2. Re: Go to cell and alert contents
            Unique Level 1

            Sorry for the confusion Kai,

             

            I do want to find the contents which is in column "Mate" and row 71247.

             

            just a x-y co-ordinates which meet at the column Mate and Row which has cell contents "71247"

             

            Untitled-1.jpg

             

            thanks for the reply Kai.

            • 3. Re: Go to cell and alert contents
              Laubender Adobe Community Professional & MVP

              @Unique – every cell has a parentRow property. So if you found a cell, look at its parentRow.cells[-1] to get the last cell of that parent row and read out its contents.

               

              Uwe

              • 4. Re: Go to cell and alert contents
                Laubender Adobe Community Professional & MVP

                @Unique – there is a fantastic documentation of the DOM (Document Object Model) where you can look up all properties and methods for the objects. I recommend downloading the chm-files, because they are  easily searchable:

                 

                Jongware

                InDesign JavaScript Reference Guide

                http://www.jongware.com/idjshelp.html

                 

                Uwe

                1 person found this helpful
                • 5. Re: Go to cell and alert contents
                  Kai Rübsamen Adobe Community Professional

                  If you want to find 500 try this:

                   

                   

                  var curDoc = app.activeDocument;
                  var everyHeaderRow = curDoc.pages.everyItem(0).textFrames.everyItem().tables.everyItem().rows[0].getElements();
                  
                  
                  for( var i = 0; i<everyHeaderRow.length; i++ ) {
                    var curHR = everyHeaderRow[i];
                    var allHC = curHR.cells;
                      
                  for ( var j = 0; j < allHC.length; j++ ) {
                    if ( allHC[j].contents == "Mate" ) {
                      var curCol = allHC[j].columns[0].index;
                      var curTableCells = curHR.parent.cells;
                        for ( var c = 0; c < curTableCells.length; c++ ) {
                          var curCell = curTableCells[c];
                            if ( curCell.contents == "71247" ) {
                              var curRow = curCell.parentRow.index;
                                      var x = curCol + ":" + curRow;
                                      var curName = curTableCells.item(x);
                              alert(curName.contents);
                           }
                        }
                      }
                    }
                  }
                  
                  • 6. Re: Go to cell and alert contents
                    Unique Level 1

                    Hi Laubender & 5.Kai Rübsamen,

                     

                    Many apologise for my request.

                     

                    I m not a programmer like you people.

                     

                    I tried in this way before i got answer from you people.

                     

                     

                    var every = app.activeDocument.pages.everyItem(0).textFrames.everyItem().tables.everyItem().cells.eve ryItem().getElements();

                    // Would be so cool:

                    var T = [];

                    var m = [];

                    var sn = [];

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

                    if(every[i].contents =="71247") {

                    //~

                    app.findGrepPreferences.findWhat = "Null";

                              app.activeDocument.findGrep(true);

                              var fnd = app.activeDocument.findGrep();

                     

                              for(y=0; y<fnd.length; y++) {

                                        if(fnd[y].length>0 &&

                     

                     

                                        T.push(fnd[y].parent.name));

                     

                     

                                        m.push(every[i].name);

                                        var f= (m).join("\r").replace(":", ".");

                                        var e = (T).join("\r").replace(":", ".");

                                        r = [];

                                        r.push(e.split('.')[0]);

                                        //alert (r);

                     

                    g = [];

                                                  g.push(f.split('.')[0]);

                              //alert(g);

                                        var u = f-e;

                                        var n = [];

                                        n.push(u);

                                        Found = [];

                                        Found.push(g-r);

                                        app.select((every[i-Found]));

                                        sn.push(every[i-Found].contents);

                          }

                    }

                    }

                    alert (sn);

                     

                     

                    Sorry for troubling you guys. I want to learn the proper method to create script like you people have created. I m really happy the way you have presented. and im ashamed of what i have done. but i want to simply my method.

                     

                    Laubender. As far i known, whenever anyone post in the forum you and jump_over [jareak] would always answer for any kind of stupid questions.

                     

                    thanks Laubender and let me know how can i learn from you.

                     

                    my id. is. raji27_siva@yahoo.co.in.

                     

                    many thanks.

                    • 7. Re: Go to cell and alert contents
                      Unique Level 1

                      i got what i need from you,

                       

                      Kai Rübsamen,

                       

                      my is is raji27_siva@yahoo.co.in.

                       

                      many many thanks or this kai.... please keep in touch with me...

                      Go to cell and alert contents