0 Replies Latest reply on Apr 16, 2012 11:17 AM by tippex321

    How to apply a certain paragraph style to a table column ?

    tippex321

      Hello,

       

      I have written following small code in order to apply a paragraph style to the first table column.

       

       

      main();

      function main()

      {

       

          if ( app.documents.length > 0 )

              {

                 var thisDoc = app.activeDocument;

                  //var _Absatzformat =app.activeDocument.paragraphStyles.itemByName("absArtikelNummer (Fotos)");

       

                 var memUnits = thisDoc.getUnits();

                 var ObjStyleToApply = app.activeDocument.objectStyles.itemByName("objXMLTableStyle");

                 var myParagraphStyle = thisDoc.paragraphStyles.itemByName("Sp1TbAbsArtikelNummer");

       

                  thisDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;

                  thisDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;

             

                  for (var myCounter = 2; myCounter < thisDoc.spreads.length; myCounter ++)

                  {

                     for(var pg=0;pg < thisDoc.spreads[myCounter].pages.length; pg ++)

                     {

                    

                          var myPageTextFrames = app.activeDocument.spreads[myCounter].pages[pg].textFrames;

       

                          oneTF = 0;

                     

                          for (var oneTF = 0; oneTF < myPageTextFrames.length; oneTF ++)

                          {

                             

                              thisTable = myPageTextFrames.item(oneTF).tables;

                             

                              if ( thisTable.length > 0 ) // => Textframe contains at least one table

                                  {

                                                                  

                                     myPageTextFrames[oneTF].applyObjectStyle(ObjStyleToApply, true );

                                      

                                     var aktuelleZelle = 0;

                                     

                                      for (var oneTableRow = 0; oneTableRow < thisTable[0].rows.length; oneTableRow ++)

                                      {

                                         

                                          thisTable[0].cells [aktuelleZelle].paragraphs.firstItem().applyParagraphStyle (myParagraphStyle,true); // Error occurs: 45 Object does not exist

                                          aktuelleZelle += 7;

                                          thisTable[0].rows[oneTableRow].verticalJustification = VerticalJustification.CENTER_ALIGN;

                                          thisTable[0].rows[oneTableRow].minimumHeight = 5.3;

                                                                     

                                      }

                                 

                                  }

                             

                          }                           

                   }

               }

              

          }

      }

       

      I am using Indesign CS 5.5 (Windows 7 64 Bit).

      When executing the script, ID stops always stops at this line:

             thisTable[0].cells [aktuelleZelle].paragraphs.firstItem().applyParagraphStyle (myParagraphStyle,true);

       

      Any idea ?

       

      Thank you, in advance.

      Steven