1 Reply Latest reply on Mar 22, 2012 10:32 AM by Laubender

    Table Column want to fix with TextWidth

    Learner X Level 1

      Hi,

       

      I have script in that it apply cell styles as per paragraph styles.  But my doubt follows:

       

       

      First Doubt:

       

      But i need after applying cell styles it automatically fit with their textwidth (for example textwidth is 36P)

       

       

      Second Doubt:

       

      Why cell styles not apply for empty cells?

       

      //Script start here

       

      myDoc = app.activeDocument;

      function tableStyle(pStyle, cellStyle)

      {

          app.findTextPreferences.appliedParagraphStyle= pStyle;

          myFoundItems = myDoc.findText(); 

          if (myFoundItems.length != 0) {

                  for (i = 0; i <= myFoundItems.length - 1; i++) {

                      var myFoundItem = myFoundItems[i];

                      myCell=myFoundItem.parent;

                      myCell.appliedCellStyle = cellStyle;

                      //myCell.appliedCellStyle = myDoc.cellStyles.item(cellStyle);

                      myCell.clearCellStyleOverrides(true);

                      }

                  }

              app.findTextPreferences = null;

          }

       

      app.findTextPreferences = null;

      tableStyle ("TCH", "TCH");

      tableStyle ("TB", "TB");

      tableStyle ("TB_L", "TB_L");

       

       

       

       

      For your information i attached.

       

       

      Screen Shot 2012-03-21 at 11.59.18 PM.png

       

       

       

      Please give any solution for the above mentioned queries.

       

      Because currently i am doing book contains 20 tables in each chapter. Book contains 25 chapters.

       

      Thanks in advance......

        • 1. Re: Table Column want to fix with TextWidth
          Laubender Adobe Community Professional & MVP

          The problem is: your search routine will skip all cells that have no contents.
          If you would loop through all cells of all tables of all stories of your document and  ask for the appliedParagraphStyle for the first insertion point you will succeed:

           

          //For a given table "myTable" and a given cell style "myCellStyle":
          
          for(var n=0;myTable.cells.length;n++){
              if(myTable.cells[n].insertionPoints[0].appliedParagraphStyle == myPStyle){
                  myTable.cells[n].appliedCellStyle = myCellStyle;
                  /*
               ...         
               do the rest of your stuff
               ...
               */
                  };
              };
          

           

          Explanation: an otherwise empty cell contains one single insertion point! And that insertion point has to have formatting information.

           

          Uwe