0 Replies Latest reply on Oct 27, 2014 10:09 AM by VeluVK

    Adjusting Column width

    VeluVK Level 1

      Hi Chinna/anyone

      I tried little bit changes in your (Chinnadk) previous script (see below), can you please check and correct?


      1) Can you please include (superscript character) columns into 1pica width

      2) Sometimes empty columns are not converted into "1p" because of spanning (see the below table), Can you please ignore the spanned columns while running the script or put any input dialogue box for "number of rows to ignore".


      input.JPG

       

         

      var doc = app.activeDocument, 

          w = doc.documentPreferences.pageWidth; 

          sel = doc.selection[0];

       

          if(sel instanceof Table) 

          { 

                  var col = sel.columns; 

                      _left = sel.parent.parentPage.marginPreferences.left; 

                      _right = sel.parent.parentPage.marginPreferences.right, allcolwidth = 0; 

                  for(var i=1;i<col.length;i++) 

                  { 

                          var cell = col[i].cells, cont = ""; 

                          for(var j=0;j<cell.length;j++) 

                          { 

                                  cont += cell[j].contents; 

                              } 

                          if(cont == "") 

                          { 

                                  col[i].width = "1p"; 

                                  allcolwidth += col[i].width; 

                              } 

                          else if(cont.indexOf("$") !=-1) 

                          { 

                                  col[i].width = "1p"; 

                                  allcolwidth += col[i].width; 

                              } 

                          else if(cont.indexOf("*") !=-1) 

                          { 

                                  col[i].width = "1p"; 

                                  allcolwidth += col[i].width; 

                                 

                              } 

                          else if(cont.indexOf("%") !=-1) 

                          { 

                                  col[i].width = "1p"; 

                                  allcolwidth += col[i].width; 

       

                              } 

                         else if(cont.indexOf(")") !=-1) 

                          { 

                                  col[i].width = "1p"; 

                                  allcolwidth += col[i].width; 

       

                              } 

                  

                          else 

                          { 

                                  col[i].width = "5p"; 

                                  allcolwidth += col[i].width; 

                                  for(var k=0;k<col[i].cells.length;k++) 

                                  { 

                                          if(col[i].cells[k].contents !="") 

                                          { 

                                                  var paras = col[i].cells[k].paragraphs; 

                                                  for(var l=0;l<paras.length;l++) 

                                                  { 

                                                          paras[l].justification = Justification.RIGHT_ALIGN; 

                                                      } 

                                              } 

                                      } 

                              } 

                      } 

                  col[0].width = w - _left - _right - allcolwidth; 

              } 

          else 

          { 

                  alert("Select a table...") 

              }

       

       

      Regards,

      Velu