5 Replies Latest reply on Sep 10, 2008 2:39 AM by (Dave_Saunders)

    Find text in a table cell and apply a character style

      Hi,

      I have a table cell that has some text in it like "EXAMPLE TEXT: This is an example text". I want to apply a character style only to the text "EXAMPLE TEXT:" and not all the text in the cell. How can I do this?

      My attempts so far have led me to the following code that obviously does not work:
      //style "EXAMPLE TEXT:" ect
      //Search the document for the string "EXAMPLE TEXT:".
      app.findTextPreferences.findWhat = "EXAMPLE TEXT:";
      var myFoundItems = myTableCell.findText();
      //Now apply a style
      myFoundItems.item[0].appliedCharacterStyle = myCharacterStyle;

      Thanks,

      Dean
        • 1. Re: Find text in a table cell and apply a character style
          Level 1
          I gave up to soon! I was already so close! The solution is below. I was simply not using the array properly - so dumb of me...

          //style "EXAMPLE TEXT:" ect
          //Search the document for the string "EXAMPLE TEXT:".
          app.findTextPreferences.findWhat = "EXAMPLE TEXT:";
          var myFoundItems = myTableCell.findText();
          //Now apply a style
          myFoundItems[0].appliedCharacterStyle = myCharacterStyle;

          I'm sorry to anyone who has already spent time trying to help me but hasn't replied yet.

          cheers,

          Dean
          • 2. Re: Find text in a table cell and apply a character style
            subhaoviya Level 1
            while am trying the above code, i got an error like
            "invalid value of set property 'applied character style' expected character style, but received nothing".

            how to overcome this ?

            myFoundItems[0].appliedCharacterStyle = myCharacterStyle
            the error is from the above line, and also i cant able to set the paragraph style.

            i tried out this in two way

            myFoundItems[0].appliedCharacterStyle = "character style name"
            myFoundItems[0].appliedCharacterStyle =app.activeDocument.characterStyles.item("character style name")

            not working...
            help me

            thanks
            subha
            • 3. Re: Find text in a table cell and apply a character style
              subhaoviya Level 1
              i got this above mentioned error only when i but the paragraphstyle in a folder inside the paragraphstyle palatte.

              how to handle this?

              thanks
              subha
              • 4. Re: Find text in a table cell and apply a character style
                subhaoviya Level 1
                i got it friends

                the syntex is
                app.selection[0].appliedCharacterStyle =app.activeDocument.characterStyleGroups.item(characterstylefoldername).characterStyles.i tem(characterstylename);
                • 5. Re: Find text in a table cell and apply a character style
                  Level 1
                  Well done. One thing I've been doing lately is working with a document where classes of paragraph styles are held in particular folders. In some cases, I've needed to perform an operation on all text in any of the styles in a folder. Rather than do a search for each such style, I've been using something like this:
                      setupFindGrep("\\(\\d+\\)");
                  
                      var myFinds = story.findGrep();
                      for (j = myFinds.length - 1; j >= 0; j--) {
                        var parentName = myFinds[j].appliedParagraphStyle.parent.name;
                        if (parentName == "Table_Text_Styles" || (parentName == "Table_Figure_Styles" &&
                              myFinds[j].appliedParagraphStyle.name.indexOf("_N") == -1)) {
                          myFinds[j].appliedCharacterStyle = "Footnote_Reference";
                        }
                      }
                  In the early days, I cursed those folders, but used wisely, they can make more complex searches like this easier to code.

                  Dave

                  PS: setupFindGrep is a function that sets up a Grep search (there's a surprise). I think I've posted it elsewhere on the forum already.