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 Aug 11, 2022 10:09 am

Hello,

I want to change a word's color ,bold info underline info in a text but text is in paragraph and when I want to change normally it changes all text's color.

Code: Select all
(item as IAutoShape).TextFrame.Paragraphs[0].Text = (item as IAutoShape).TextFrame.Paragraphs[0].Text.Replace(key, value); // value is the word I want to change settings
(item as IAutoShape).TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid;
(item as IAutoShape).TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.Red;
(item as IAutoShape).TextFrame.Paragraphs[0].TextRanges[0].IsBold = TriState.True;
(item as IAutoShape).TextFrame.Paragraphs[0].TextRanges[0].TextUnderlineType = TextUnderlineType.Single;


Is there a way of changing settings of a part of text?

numankizil
 
Posts: 26
Joined: Tue Nov 09, 2021 8:00 pm

Fri Aug 12, 2022 8:50 am

Hello,

Thanks for your inquiry.

TextRange is the smallest object of text manipulation. So for text in the same TextRange, they are always bound by the same style. So currently we don't support the scenario you mentioned. But we will consider it as a development plan for new features. I have recorded it with ticket number SPIREPPT-2037. I'll keep you informed if we implement this feature in the future. Sorry for the inconvenience.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Wed Sep 07, 2022 5:45 pm

Is there a workaround maybe? Is there a way for us to break the text into 2 paragraphs and change the font settings of one of the paragraphs?

majeed_s
 
Posts: 69
Joined: Thu Mar 25, 2021 4:13 pm

Thu Sep 08, 2022 1:07 am

Hi,

Good morning!

Yes, we're going to provide a method for finding specific text in a slide and putting it into a TextRange by itself and returning it. At this point you can set the font style and color for it individually. We have preliminarily completed this method and are conducting various tests and verifications. I will keep you informed when new version is available.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Thu Sep 08, 2022 10:44 am

Thanks for the update!

majeed_s
 
Posts: 69
Joined: Thu Mar 25, 2021 4:13 pm

Tue Sep 27, 2022 10:16 am

Hi,

Thanks for your patient waiting.
Glad to inform you that the feature is done. Please download the hotfix (Spire.Presentation Pack Hotfix Version:7.9.2) and refer to the code below.
Website download link: https://www.e-iceblue.com/Download/download-presentation-for-net-now.html
Nuget download link: https://www.nuget.org/packages/Spire.Presentation/7.9.2
Code: Select all
 Presentation ppt = new Presentation();
 ppt.LoadFromFile(inputFile);
 string text = "create, read";
 TextRange textRange = ppt.Slides[0].FindFirstTextAsRange(text);
 textRange.Fill.FillType = FillFormatType.Solid;
 textRange.Fill.SolidColor.Color = Color.Red;
 textRange.FontHeight = 28;
 textRange.LatinFont = new TextFont("微软雅黑");
 textRange.IsBold = TriState.True;
 textRange.IsItalic = TriState.True;
 textRange.TextUnderlineType = TextUnderlineType.Double;
 textRange.TextStrikethroughType = TextStrikethroughType.Single;
 presentation.SaveToFile(result, FileFormat.Pptx2013);


Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.Presentation