Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files from any .NET platform (C#, VB.NET, ASP.NET, .NET Core) and Java applications (J2SE and J2EE) with fast and high quality performance.

Mon Apr 13, 2020 7:43 pm

Hi, following tutorials on the docs, I'm using Paragraph to insert a text on my Word Document.
But, I want to style just some word's in a string, and maybe add some special caracter like "•"

How can I do that?

Styled string example:
WARNING: How should I do this?

kevinka999
 
Posts: 16
Joined: Wed Apr 08, 2020 7:09 pm

Tue Apr 14, 2020 3:57 am

Hello,

Thanks for your post.
For your requirement, please refer to the following code to achieve it.
Code: Select all
  Document document = new Document();
            Section section = document.AddSection();
            Paragraph paragraph = section.AddParagraph();
            String text1 = "WARNING";
            TextRange textRange1=new TextRange(document);
            textRange1.Text = text1;
            textRange1.CharacterFormat.FontName = "Arial";
            textRange1.CharacterFormat.FontSize = 10;
            textRange1.CharacterFormat.Bold=true;
            textRange1.CharacterFormat.UnderlineStyle= UnderlineStyle.Single;
            paragraph.ChildObjects.Add(textRange1);

            String text2 = ": How should I do this?";
            TextRange textRange2 = new TextRange(document);
            textRange2.Text = text2;
            textRange2.CharacterFormat.FontName = "Arial";
            textRange2.CharacterFormat.FontSize = 10;
            paragraph.ChildObjects.Add(textRange2);

            //If you want to add some special caracter like "•" in an existing paragraph
            TextRange textRange0 = new TextRange(document);
            textRange0.Text = "• ";
            paragraph.ChildObjects.Insert(0, textRange0);

            document.SaveToFile(output, FileFormat.Docx2013);

Output:
output.png


If it is not what you wish, please let me know.

Sincerely,
Amy
E-iceblue support team
You do not have the required permissions to view the files attached to this post.
User avatar

amy.zhao
 
Posts: 2448
Joined: Wed Jun 27, 2012 8:50 am

Fri Apr 17, 2020 10:25 am

Hello,

Hope you are doing well.
Have you tested my code? Does it meet your needs?
Any feedback will be greatly appreciated!

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2448
Joined: Wed Jun 27, 2012 8:50 am

Fri Apr 17, 2020 6:20 pm

Yeah, that's worked!
Thanks ;)

kevinka999
 
Posts: 16
Joined: Wed Apr 08, 2020 7:09 pm

Mon Apr 20, 2020 1:34 am

Hello,

Thanks for your feedback.
Glad to hear that it worked.
Feel free to contact us if you have any other problems.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2448
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc