RunProperties Constructors

Definition

Overloads

RunProperties()

Initializes a new instance of the RunProperties class.

RunProperties(OpenXmlElement[])

Initializes a new instance of the RunProperties class with the specified child elements.

RunProperties(IEnumerable<OpenXmlElement>)

Initializes a new instance of the RunProperties class with the specified child elements.

RunProperties(String)

Initializes a new instance of the RunProperties class from outer XML.

RunProperties()

Initializes a new instance of the RunProperties class.

C#
public RunProperties ();

Examples

The following code example creates a word processing document and writes some text into it using specific fonts. After you run the example examine the created test file to see the text.

C#
using System;  
using System.Collections.Generic;  
using DocumentFormat.OpenXml;  
using DocumentFormat.OpenXml.Packaging;  
using DocumentFormat.OpenXml.Wordprocessing;  

namespace RunPropertiesEx  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            // This example creates a word processing document and writes  
            // some text into it using specific fonts.  
            string filepath = @"C:\Users\Public\Documents\RunPropertiesEx.docx";  
            using (WordprocessingDocument source =   
                WordprocessingDocument.Create(filepath, WordprocessingDocumentType  
                .Document))  
            {  
                // Create a Document, Body, and Paragraph objects.  
                MainDocumentPart mainPart = source.AddMainDocumentPart();  
                mainPart.Document = new Document();  
                Body body = mainPart.Document.AppendChild(new Body());  
                Paragraph paragraph = body.AppendChild(new Paragraph());  

                // Append a run as source and set its Attributes.  
                Run srcRunElem = paragraph.AppendChild(new Run(new  
                    Text("Hello, World!")));  
                RunProperties rPr1 = new RunProperties(new RunFonts()   
                    { Ascii = "Palace Script MT",   
                    Hint = FontTypeHintValues.ComplexScript },  
                    new Color() { Val = "FF0000" }, new FontSize()   
                    { Val = "84" });  

                // Prepend the RunProperties to the Run.  
                srcRunElem.PrependChild<RunProperties>(rPr1);  

                // Append another run as target and set its Attributes.  
                Run targetRun = paragraph.AppendChild(new Run(new Text  
                    ("Hello again")));  
                RunProperties rPr2 = new RunProperties(new RunFonts()   
                { Ascii = "Algerian" }, new Color() { Val = "FF00FF" },   
                new FontSize() { Val = "64" });  

                // Prepend the RunProperties to the Run.  
                targetRun.PrependChild<RunProperties>(rPr2);  

                // Get the SlideSize RunFonts form source and target.  
                RunFonts srcRunFontsElem = srcRunElem.RunProperties.RunFonts;  
                RunFonts tgtRunFontsElem = targetRun.RunProperties.RunFonts;  

                // Retrieve Attributes of the source element.  
                IList<OpenXmlAttribute> srcRunFontsAttrs = srcRunFontsElem.GetAttributes();  
                Console.WriteLine("Source Fonts:");  
                foreach (OpenXmlAttribute a in srcRunFontsAttrs)  
                {  
                    Console.WriteLine("{0}: {1}", a.LocalName, a.Value);  
                }  

                // Call SetAttributes on target RunFonts, changes will be accpeted to target.  
                // Ascii is updated. And Hint which didn't exist in target, is appended.  
                tgtRunFontsElem.SetAttributes(srcRunFontsAttrs);  
                Console.WriteLine("Target Fonts after setting:");  
                foreach (OpenXmlAttribute a in tgtRunFontsElem.GetAttributes())  
                {  
                    Console.WriteLine("{0}: {1}", a.LocalName, a.Value);  
                }  

                Console.WriteLine("All done. Press a key.");  
                Console.ReadKey();  
            }  
        }  
    }  
}  
//Output:  
//Source Fonts:  
//hint: cs  
//ascii: Palace Script MT  
//Target Fonts after setting:  
//hint: cs  
//ascii: Palace Script MT  
//All done. Press a key.  
Imports System.Collections.Generic  
Imports DocumentFormat.OpenXml  
Imports DocumentFormat.OpenXml.Packaging  
Imports DocumentFormat.OpenXml.Wordprocessing  

Module Module1  

    Sub Main(ByVal args As String())  
        ' This example creates a word processing document and writes  
        ' some text into it using specific fonts.  
        Dim filepath As String = "C:\Users\Public\Documents\RunPropertiesEx.docx"  
        Using source As WordprocessingDocument = WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document)  
            ' Create a Document, Body, and Paragraph objects.  
            Dim mainPart As MainDocumentPart = source.AddMainDocumentPart()  
            mainPart.Document = New Document()  
            Dim body As Body = mainPart.Document.AppendChild(New Body())  
            Dim paragraph As Paragraph = body.AppendChild(New Paragraph())  

            ' Append a run as source and set its Attributes.  
            Dim srcRunElem As Run = paragraph.AppendChild(New Run(New Text("Hello, World!")))  
            Dim rPr1 As New RunProperties(New RunFonts() With { _  
             .Ascii = "Palace Script MT", _  
             .Hint = FontTypeHintValues.ComplexScript _  
            }, New Color() With { _  
             .Val = "FF0000" _  
            }, New FontSize() With { _  
             .Val = "84" _  
            })  

            ' Prepend the RunProperties to the Run.  
            srcRunElem.PrependChild(Of RunProperties)(rPr1)  

            ' Append another run as target and set its Attributes.  
            Dim targetRun As Run = paragraph.AppendChild(New Run(New Text("Hello again")))  
            Dim rPr2 As New RunProperties(New RunFonts() With { _  
             .Ascii = "Algerian" _  
            }, New Color() With { _  
             .Val = "FF00FF" _  
            }, New FontSize() With { _  
             .Val = "64" _  
            })  

            ' Prepend the RunProperties to the Run.  
            targetRun.PrependChild(Of RunProperties)(rPr2)  

            ' Get the SlideSize RunFonts form source and target.  
            Dim srcRunFontsElem As RunFonts = srcRunElem.RunProperties.RunFonts  
            Dim tgtRunFontsElem As RunFonts = targetRun.RunProperties.RunFonts  

            ' Retrieve Attributes of the source element.  
            Dim srcRunFontsAttrs As IList(Of OpenXmlAttribute) = srcRunFontsElem.GetAttributes()  
            Console.WriteLine("Source Fonts:")  
            For Each a As OpenXmlAttribute In srcRunFontsAttrs  
                Console.WriteLine("{0}: {1}", a.LocalName, a.Value)  
            Next  

            ' Call SetAttributes on target RunFonts, changes will be accpeted to target.  
            ' Ascii is updated. And Hint which didn't exist in target, is appended.  
            tgtRunFontsElem.SetAttributes(srcRunFontsAttrs)  
            Console.WriteLine("Target Fonts after setting:")  
            For Each a As OpenXmlAttribute In tgtRunFontsElem.GetAttributes()  
                Console.WriteLine("{0}: {1}", a.LocalName, a.Value)  
            Next  

            Console.WriteLine("All done. Press a key.")  
            Console.ReadKey()  
        End Using  
    End Sub  
End Module  
'Output:  
'Source Fonts:  
'hint: cs  
'ascii: Palace Script MT  
'Target Fonts after setting:  
'hint: cs  
'ascii: Palace Script MT  
'All done. Press a key.  

Applies to

DocumentFormat.OpenXml 3.0.1 an aner Versiounen
Produkt Versiounen
DocumentFormat.OpenXml 2.7.1, 2.7.2, 2.8.0, 2.8.1, 2.9.0, 2.9.1, 2.10.0, 2.10.1, 2.11.0, 2.11.1, 2.11.2, 2.11.3, 2.12.0, 2.12.1, 2.12.2, 2.12.3, 2.13.0, 2.13.1, 2.14.0, 2.15.0, 2.16.0, 2.17.1, 2.18.0, 2.19.0, 2.20.0, 3.0.0, 3.0.1

RunProperties(OpenXmlElement[])

Initializes a new instance of the RunProperties class with the specified child elements.

C#
public RunProperties (params DocumentFormat.OpenXml.OpenXmlElement[] childElements);

Parameters

childElements
OpenXmlElement[]

Specifies the child elements.

Applies to

DocumentFormat.OpenXml 3.0.1 an aner Versiounen
Produkt Versiounen
DocumentFormat.OpenXml 2.7.1, 2.7.2, 2.8.0, 2.8.1, 2.9.0, 2.9.1, 2.10.0, 2.10.1, 2.11.0, 2.11.1, 2.11.2, 2.11.3, 2.12.0, 2.12.1, 2.12.2, 2.12.3, 2.13.0, 2.13.1, 2.14.0, 2.15.0, 2.16.0, 2.17.1, 2.18.0, 2.19.0, 2.20.0, 3.0.0, 3.0.1

RunProperties(IEnumerable<OpenXmlElement>)

Initializes a new instance of the RunProperties class with the specified child elements.

C#
public RunProperties (System.Collections.Generic.IEnumerable<DocumentFormat.OpenXml.OpenXmlElement> childElements);

Parameters

childElements
IEnumerable<OpenXmlElement>

Specifies the child elements.

Applies to

DocumentFormat.OpenXml 3.0.1 an aner Versiounen
Produkt Versiounen
DocumentFormat.OpenXml 2.7.1, 2.7.2, 2.8.0, 2.8.1, 2.9.0, 2.9.1, 2.10.0, 2.10.1, 2.11.0, 2.11.1, 2.11.2, 2.11.3, 2.12.0, 2.12.1, 2.12.2, 2.12.3, 2.13.0, 2.13.1, 2.14.0, 2.15.0, 2.16.0, 2.17.1, 2.18.0, 2.19.0, 2.20.0, 3.0.0, 3.0.1

RunProperties(String)

Initializes a new instance of the RunProperties class from outer XML.

C#
public RunProperties (string outerXml);

Parameters

outerXml
String

Specifies the outer XML of the element.

Applies to

DocumentFormat.OpenXml 3.0.1 an aner Versiounen
Produkt Versiounen
DocumentFormat.OpenXml 2.7.1, 2.7.2, 2.8.0, 2.8.1, 2.9.0, 2.9.1, 2.10.0, 2.10.1, 2.11.0, 2.11.1, 2.11.2, 2.11.3, 2.12.0, 2.12.1, 2.12.2, 2.12.3, 2.13.0, 2.13.1, 2.14.0, 2.15.0, 2.16.0, 2.17.1, 2.18.0, 2.19.0, 2.20.0, 3.0.0, 3.0.1