Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Thu Mar 19, 2015 4:36 pm

Is there way to mix the font sizes or styling of text within a single TextRange? For example, how would I add text formatted in this way to a TextRange:

Here is my text. Only a few words are in bold, and some are underlined.

It seems that I am only able to change these properties for the entire TextRange.

jhumber
 
Posts: 5
Joined: Mon Mar 16, 2015 9:27 pm

Fri Mar 20, 2015 10:04 am

Hello,

Thanks for your inquiry.
There is way to mix the font sizes or styling of text within a single TextRange. You can extract the texts that you want to set the format. Next,set its format and append them to paragraph. Please try the following code.
Code: Select all
            Presentation ppt = new Presentation("Sample.pptx", FileFormat.Pptx2010);
            IAutoShape shape = ppt.Slides[0].Shapes[0] as IAutoShape;
            string originalText = shape.TextFrame.Text;
            string[] splitArray = originalText.Split(new string[] { "bold", "underlined" }, StringSplitOptions.None);
            TextParagraph tp = shape.TextFrame.TextRange.Paragraph;
            tp.TextRanges.Clear();
            //normal text
            TextRange tr = new TextRange(splitArray[0]);
            tp.TextRanges.Append(tr);
            //bold text
            tr = new TextRange("bold");
            tr.IsBold = TriState.True;
            tp.TextRanges.Append(tr);
            //normal text
            tr = new TextRange(splitArray[1]);
            tp.TextRanges.Append(tr);
            //underline text
            tr = new TextRange("underlined");
            tr.TextUnderlineType = TextUnderlineType.Single;
            tp.TextRanges.Append(tr);
            //normal text
            tr = new TextRange(splitArray[2]);
            tp.TextRanges.Append(tr);
            ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);


Best Regards,
Sweety
E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Mon Mar 23, 2015 6:59 am

Hello,

Has your issue been resolved? Could you please give us some feedback at your convenience?

Best Regards,
Sweety
E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Mon Mar 23, 2015 4:04 pm

sweety1 wrote:Hello,

Has your issue been resolved? Could you please give us some feedback at your convenience?

Best Regards,
Sweety
E-iceblue support team


Yes, that is exactly what I needed. Thanks!

jhumber
 
Posts: 5
Joined: Mon Mar 16, 2015 9:27 pm

Tue Mar 24, 2015 1:36 am

Hello,

Please feel free to contact us, if you have any questions or needs. We are here for help.

Sincerely,,
Sweety
E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Return to Spire.Presentation