Issue to have bold effect

Peter_1985 2,466 Reputation points
2021-10-31T06:57:35.717+00:00

Hi,
How to correct the line below, to have Bold effect?

RunProperties runProperties = run.AppendChild(new RunProperties(new Bold { Val = BoldValues.Single }));

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,264 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,097 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,061 Reputation points
    2021-10-31T09:43:49.99+00:00

    Based on MSDN sample, this creates a .docx with a bold text =>

    string sFilePath = "Test.docx";
    using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(sFilePath, WordprocessingDocumentType.Document))
    {
        // Add a main document part. 
        MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
    
        // Create the document structure and add some text.
        mainPart.Document = new Document();
        Body body = mainPart.Document.AppendChild(new Body());
        Paragraph para = body.AppendChild(new Paragraph());
        Run run = para.AppendChild(new Run());
    
        run.Append(new Text("This is a bold text"));
        RunProperties runProperties = new RunProperties();
        runProperties.Append(new Bold());
        run.RunProperties = runProperties;
    }
    
    0 comments No comments

0 additional answers

Sort by: Most helpful