1 Reply Latest reply on Sep 11, 2013 7:23 AM by Jennifer Hearing

    How do you insert ascending numbers and letters in table cells?

    Jennifer Hearing

      Found the following script on another discussion (http://forums.adobe.com/message/5574714#5574714) . . .

       

      How can I alter it so it only adds numbers to one column, instead of every column?

      What if I  want the numbering to start in the 2nd or 3rd cell?

      And is it possible to do this with the alphabet as well as numbers?

       

      Thanks

       

      //InsertNumbersInCellsColumnByColumn_SELECTION_TABLE.jsx
      //Uwe Laubender
      /**
      * @@@BUILDINFO@@@ InsertNumbersInCellsColumnByColumn_SELECTION_TABLE.jsx !Version! Thu Nov 01 2012 07:39:54 GMT+0100
      */
       
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
       
      app.doScript(_InsertNumbersInCellsColumnByColumn, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Insert numbers in cells column by column");
       
      function _InsertNumbersInCellsColumnByColumn(){
       
      var delimiter = "\t"; //Tab after the number: "\t"; if you want nothing just set its value to: "". If you want a blank change it to: " ";
       
      var myTable = app.selection[0];
       
      if(myTable.constructor.name !== "Table"){
          alert("You have to select a Table. Script stops here.")
          exit(0);
          };
       
      var counter = 0;
      var tColumns = myTable.columns;
       
      for(var n=0;n<tColumns.length;n++){
          
          var myCellsPerColumn = tColumns[n].cells;
          
          for(var c=0;c<myCellsPerColumn.length;c++){
              counter = counter+1;
              myCellsPerColumn[c].insertionPoints[0].contents = counter.toString()+delimiter;
              };
          
          };
       
      alert("Done. "+counter+" cells were filled with numbers column by column.");
       
      };
       
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
      
      
        • 1. Re: How do you insert ascending numbers and letters in table cells?
          Jennifer Hearing Level 1

          Tried playing around with this from another direction. I needed the first row across the top of my chart lettered (A, B, C, D, etc) and the last column down numbered (1, 2, 3, etc.). But I only needed numering and lettering in certain cells.

           

          I created 4 paragraph styles in InDesign:

          1. chart number blue (numbering set to "continue from previous")

          2. chart number blue 2 (numbering set to "start at 1")

          3. chart letter blue (numbering set to "start at 1")

          4. chart letter blue 2 (numbering set to "continue from previous")

           

          I used javascript to add a row and column, then assigned the "continue from previous" paragraph styles to the row and column. Then I inserted a "non-space" figure (end-nested style) that triggers the paragraph styles numbering to appear . (It doesn't show up  once I paste it here, but in javascript the code for end nested style is a red highlighted "ETX".) Then I assigned a different paragraph style to the cells  which did not need a number/letter. And lastly, I assigned the paragraph styles that "start at 1" in the appropriate cells so the numbering and lettering would start again, no matter how many tables preceeded. Got the idea from the following article and adjusted as needed: http://indesignsecrets.com/how-to-number-your-rows-in-a-table.php.

           

          table = app.selection[0];

          if (table.hasOwnProperty("baseline")) table = table.parent;

          if (table instanceof Cell) table = table.parent;

          if (table instanceof Column) table = table.parent;

          if (table instanceof Row) table = table.parent;

          if (table instanceof Table)

           

          // Add row to top [0]

          myRow = table.rows[0];

           

          for (a=0; a<1; a++){

           

               table.rows.add(LocationOptions.BEFORE, myRow);

               // Need to re-resolve myRow!

               myRow.getElements();

          }

           

          // Add column to end [-1]

          myColumn = table.columns[-1];

          for (a=0; a < 1; a++)

           

          {

              table.columns.add(LocationOptions.AFTER, myColumn);

          }

           

          // Apply chart NUMBER paragraph styles to last column

          {

                      table.columns[-1].cells.everyItem().texts.everyItem().appliedParagraphStyle = "chart number blue";

          }

          {

                      table.columns[-1].cells.everyItem().insertionPoints[0].contents =  ("  ");

          }

          {

                      table.columns[-1].cells[0].texts.everyItem().appliedParagraphStyle = "chart text";

          }

          {

                      table.columns[-1].cells[1].texts.everyItem().appliedParagraphStyle = "chart text";

          }

          {

                      table.columns[-1].cells[2].texts.everyItem().appliedParagraphStyle = "chart text";

          }

          {

                      table.columns[-1].cells[3].texts.everyItem().appliedParagraphStyle = "chart number blue 2";

          }

           

          // Apply chart LETTER paragraph styles to first row

          {

                      table.rows[0].cells.everyItem().texts.everyItem().appliedParagraphStyle = "chart letter blue 2";

          }

          {

                      table.rows[0].cells.everyItem().insertionPoints[0].contents =  (" ");

          }

          {

                      table.rows[0].cells[0].texts.everyItem().appliedParagraphStyle = "chart text";

          }

          {

                      table.rows[0].cells[1].texts.everyItem().appliedParagraphStyle = "chart text";

          }

          {

                      table.rows[0].cells[-1].texts.everyItem().appliedParagraphStyle = "chart text";

          }

          {

                      table.rows[0].cells[2].texts.everyItem().appliedParagraphStyle = "chart letter blue";

          }