Set the font for a text run is not working
- Dominant language
- C#
- Stars
- 4.6k
- Forks
- 605
- PR merge metrics
- No merged PRs in 30d
Description
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.
```csharp
// 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.
Contributor guide
Research direction
Start with the Microsoft Open XML how-to linked in the issue and reproduce SetRunFont with the supplied C# snippet. Inspect the saved document's first text run for the requested Arial font and determine what additional context is needed to explain why the change is not visible; done means a confirmed diagnosis or corrected documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100