Share via

Issue to have bold effect

Scott Huang 3,511 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 }));

Developer technologies | .NET | Other
Developer technologies | C#
Developer technologies | 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.

0 comments No comments

Answer accepted by question author

Castorix31 91,876 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;
}

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.