4 Replies Latest reply on Mar 15, 2013 1:31 AM by Jump_Over

    how to apply a Paragraphstyle to the text in a Cell

    maxhodges0 Level 1

      I have to apply a paragraphy style to some substring in a Cell, but nothing is working. Which property or method of the Cell do I set = myParagraphStyle?

       

      I'm on VB but any scripting code sample should sort me out I think.

       

       

      Cheers!

        • 1. Re: how to apply a Paragraphstyle to the text in a Cell
          maxhodges0 Level 1

          OK I see I can do this

               inDesignApp.Selection = para.Characters.ItemByRange(1, 1)

               inDesignApp.Selection.Item(1).appliedCharacterStyle = mycharstyle

           

          But is there anyway I can peek at the contents of this Selection? Or the contents of whatever "ItemByRange" returns? I need to apply a format only to numbers. But I can't find a way to  actually look at the text/contents/characters using this selection method.

          • 2. Re: how to apply a Paragraphstyle to the text in a Cell
            maxhodges0 Level 1

            OK got it. I can peek at para.contents.tostring

            • 3. Re: how to apply a Paragraphstyle to the text in a Cell
              maxhodges0 Level 1

              How can I select a substring of text from my Cell, so that I can apply a character style?

              This works fine when I'm only selecting a single character:

              If IsNumeric(para.Contents.ToString.Substring(0, 1)) doc.Selection = para.Characters.ItemByRange(1, 1) doc.Selection.Item(1).appliedCharacterStyle = mycharstyle End If

              but it fails if I try to select a range of characters

              doc.Selection = myCell.Characters.ItemByRange(72, 76)

              The error is

              Invalid valid for set property 'Selection. Expected Array of Objects, Object or idNothingEnum enumerator, but received (Character, Character, Character, Character, Character)

              I think there must be some entirely different technique to apply my CharacterStyle to a substring of text in my Cell, but after searching high-and-low I've yet to discover it.

              • 4. Re: how to apply a Paragraphstyle to the text in a Cell
                Jump_Over Level 5

                Hi,

                 

                .itemByRange() gives you an array of objects.

                .appliedCharacterStyle should work with this but

                .docSelection fails, I guess.

                There is no way to select a few "uncontinuos" text objects at once.

                 

                Skip setting .selection. Use .appliedCharacterStyle directly to .itemByRange.

                or

                use .itemByRange(a,b).texts[0];

                 

                rgds

                Jarek