1 Reply Latest reply on Jan 22, 2015 12:07 PM by JeffLambert

    [AS ID CC2014] How to change character style in cells selection?

    JeffLambert

      Hi,

       

      I've been racking my brain over this one for a while now and I can't come up with something that works.

       

      I know I can use this to applied a character style to ALL my text within the selected cells.

       

      tell text 1 of cells of selection

        set applied character style to myCharacterStyle

        end tell


      Now if I want to affect only the text of cells that have a particular Paragraph style, then, it gets really complicated.


      I've tried with the whose clause like this

        tell (cells of selection whose paragraph style of text 1 is myParagraphStyle)

         try

        set properties of text 1 to {applied character style:myCharacterStyle}

        end try

        end tell


      and this:

      tell text 1 of cells of selection whose Paragraphe style is myParagraphStyle



      I've also tried with a repeat loop but can't get it to work either.

      set mySelection to cells of selection

       

        repeat with i from 1 to count of items of mySelection

        tell item i of mySelection

        tell text 1 of item i

        --if paragraph style is myParagraphStyle then

        try

        set properties of text 1 to {applied character style:myCharacterStyle}

        end try

        --end if

        end tell

        end tell

        end repeat

       

      and a bunch of other ways, but I can't figure it out. If someone knows how to do this, it would really be cool:-)

       

       

      TIA

      Jeff

        • 1. Re: [AS ID CC2014] How to change character style in cells selection?
          JeffLambert Level 1

          Ok, so I figured it out. But it's slow.

           

          Here's what I've got:

           

          tell text 1 of cells of selection

            set applied character style to myCharacterStyle

            end tell

            tell cells of selection

            set fill color to mycolor10

            end tell

            tell selection

            repeat with i from (count of cells) to 1 by -1

            tell text 1 of cell i

            try

            if applied paragraph style is myParagraphEntete then

            set applied character style to myCharacterStyleNone

            clear overrides

            end if

            if contents contains "2012" then

            set applied character style to myCharacterStyle

            end if

            if contents contains "2013" then

            set applied character style to myCharacterStyle

            end if

            if contents contains "2014" then

            set applied character style to myCharacterStyle

            end if

            end try

            end tell

            end repeat

            end tell

            end tell

          end tell



          I know I know the if then part is all messed up but I didn't know how to make the "or" work, something about not the right boolean type or something.


          As you can see, I start by applying a character style on all cells cause that way faster, then I have to go through all cells and check if they have that paragraph style where I don't want the character style, but, there is some execptions so if there is a year in those cells, that has to be with the myCharacterStyle (a semibold in that case).


          Of corse, it's not the whole script, but you get the idea with this chuck.


          Thanks

          Jeff