web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Set the font for a text run is not working

(0) ShareShare
ReportReport
Posted on by 2,122

Hi,

We want to change font and font size programmatically in a Word document using c#. To do this we have used DocumentFormate.OpenXML and apply the below code.

// Set the font for a text run.
public static void SetRunFont(string fileName)
{
// Open a Wordprocessing document for editing.
using (WordprocessingDocument package = WordprocessingDocument.Open(fileName, true))
{
// Set the font to Arial to the first Run.
// Use an object initializer for RunProperties and rPr.
RunProperties rPr = new RunProperties(
new RunFonts()
{
Ascii = "Arial"
});

Run r = package.MainDocumentPart.Document.Descendants().First();
r.PrependChild(rPr);

// Save changes to the MainDocumentPart part.
package.MainDocumentPart.Document.Save();
}
}

We have picked this code from the Microsoft site i.e. https://docs.microsoft.com/en-us/office/open-xml/how-to-set-the-font-for-a-text-run but it is not working.

Any help would be greatly appreciated.

Thank You.

I have the same question (0)
  • Nya Profile Picture
    29,064 on at

    Hi,

    Would you please specify which application you're using in Dynamics?

  • Inkey Solutions Profile Picture
    2,122 on at

    We had used this code in Web API that is calling from the Plugin.

  • Nya Profile Picture
    29,064 on at

    Hi,

    I mean you use the application you use, for example Sales Hub or Finance & Operation or something like that.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Subra Profile Picture

Subra 122

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 99 Super User 2026 Season 1

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 83 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans