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.