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

Notifications

Announcements

No record found.

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,100

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,060 on at

    Hi,

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

  • Inkey Solutions Profile Picture
    2,100 on at

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

  • Nya Profile Picture
    29,060 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 58 Most Valuable Professional

#2
#ManoVerse Profile Picture

#ManoVerse 42

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans