2 Replies Latest reply on Jul 15, 2009 7:05 AM by jenlynn11

    apply a character style

    jenlynn11

      I received help last week with a script to find empty cells in a table, place a space in those empty cells and apply a paragraph style to the cell. Now I would like help with applying a character style of "None" to the space in the cell. Here is the script that was originally given to me:

       

      for (a=0; a<app.selection[0].parent.parent.cells.length; a++)
      {
      if (app.selection[0].parent.parent.cells[a].contents.length == 0)
      {
        app.selection[0].parent.parent.cells[a].contents = " ";
        app.selection[0].parent.parent.cells[a].paragraphs[0].appliedParagraphStyle = app.activeDocument.paragraphStyles.item("Empty Cell");

      }
      }

        • 1. Re: apply a character style
          Thomas B. Nielsen Level 3

          If you have a cell selected, the folowing will apply the char style "None" (Not the same as [None]) to the first paragraph of the cell.

           

          app.selection[0].paragraphs[0].appliedCharacterStyle = app.activeDocument.characterStyles.item("None");

           

          I guess the below will do what you want, but i would think using a nested style would be easier.

           

          for (a=0; a<app.selection[0].parent.parent.cells.length; a++)
          {
          if (app.selection[0].parent.parent.cells[a].contents.length == 0)
          {
            app.selection[0].parent.parent.cells[a].contents = " ";
            app.selection[0].parent.parent.cells[a].paragraphs[0].appliedParagraphStyle = app.activeDocument.paragraphStyles.item("Empty Cell");

          app.selection[0].parent.parent.cells[a].paragraphs[0].appliedCharacterStyle = app.activeDocument.characterStyles.item("None");

          }
          }    

          • 2. Re: apply a character style
            jenlynn11 Level 1

            Thank you for pointing out that "None" was not the same as "[None]". That's what I was doing wrong. Details, details, details...which I normally pay attention to. Again, thank you!