Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Apr 24, 2019 6:48 am

Hi,
I have an isssue when i try to apply a style to a paragraph.
I have a document with some text with some bold words, underligned words etc...
But when i'm applying a style to the text, FontSize doesn't change, if i want to change the font, it doesn't work too.
And if the style contains bold as true for example, it will works only from the start of the paragraph to the first bold word in my document.
Same for color, italic and underlign.

Here the code where i apply the style
Code: Select all
[...]
foreach (SPI.Section section in doc.Sections)
            {
                foreach (SPI.Documents.Paragraph para in section.Paragraphs)
                {
                    para.ApplyStyle(SPI.Documents.BuiltinStyle.Title);
                }
            }
[...]

thbryer
 
Posts: 10
Joined: Wed Apr 24, 2019 6:33 am

Wed Apr 24, 2019 8:49 am

Hello,

Thanks for your post.
Please refer to the following sample code to achieve your demand. The attachment is my generated document. If there is any question, please share us with your testing file to further look into it. You could send it to us via email(support@e-iceblue.com).
Code: Select all
 Document doc = new Document();
 doc.LoadFromFile(@"test.docx");
 Section section =doc.Sections[0];
 for (int i = 0; i < section.Paragraphs.Count; i++)
 {
     foreach (DocumentObject childObj in section.Paragraphs[i].ChildObjects)
     {
         if (childObj is TextRange)
         {
             TextRange tr = childObj as TextRange;
             tr.CharacterFormat.FontName = "Arial";
             tr.CharacterFormat.FontSize = 20f;
             tr.CharacterFormat.Bold = true;
         }
     }
 }
 doc.SaveToFile("result.docx", Spire.Doc.FileFormat.Docx2013);
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Wed Apr 24, 2019 12:08 pm

Hi,

Thank you for your response.
I solved my problem by using Characterformat from a paragraphStyle on textRange and then apply the style to the paragraph because i needed a style name on paragraph.

thbryer
 
Posts: 10
Joined: Wed Apr 24, 2019 6:33 am

Thu Apr 25, 2019 1:10 am

Hello,

Glad to hear that! If you encounter any issue related to our products in the future, just feel free to contact us. Wish you all the best!

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Doc