Example #1
0
        public TFluent SetFontColor(OpenXmlColor color)
        {
            OpenXmlElement textBody       = this.element.GetOrCreateTextBody();
            BodyProperties bodyProperties = textBody.GetFirstChild <BodyProperties>() ?? textBody.AppendChild(new BodyProperties());

            foreach (Paragraph paragraph in textBody.Elements <Paragraph>())
            {
                ParagraphProperties  paragraphProperties  = paragraph.GetFirstChild <ParagraphProperties>() ?? paragraph.PrependChild(new ParagraphProperties());
                DefaultRunProperties defaultRunProperties = paragraphProperties.GetFirstChild <DefaultRunProperties>() ?? paragraphProperties.AppendChild(new DefaultRunProperties());
                defaultRunProperties.RemoveAllChildren <NoFill>();
                defaultRunProperties.RemoveAllChildren <SolidFill>();
                defaultRunProperties.RemoveAllChildren <GradientFill>();
                defaultRunProperties.RemoveAllChildren <BlipFill>();
                defaultRunProperties.RemoveAllChildren <PatternFill>();
                defaultRunProperties.RemoveAllChildren <GroupFill>();

                defaultRunProperties.AppendChild(new SolidFill().AppendChildFluent(color.CreateColorElement()));

                foreach (Run run in paragraph.Elements <Run>())
                {
                    RunProperties runProperties = run.GetFirstChild <RunProperties>() ?? run.PrependChild(new RunProperties());
                    runProperties.RemoveAllChildren <NoFill>();
                    runProperties.RemoveAllChildren <SolidFill>();
                    runProperties.RemoveAllChildren <GradientFill>();
                    runProperties.RemoveAllChildren <BlipFill>();
                    runProperties.RemoveAllChildren <PatternFill>();
                    runProperties.RemoveAllChildren <GroupFill>();

                    runProperties.AppendChild(new SolidFill().AppendChildFluent(color.CreateColorElement()));
                }
            }

            return(this.result);
        }
Example #2
0
        public TFluent SetFont(string typeface)
        {
            OpenXmlElement textBody       = this.element.GetOrCreateTextBody();
            BodyProperties bodyProperties = textBody.GetFirstChild <BodyProperties>() ?? textBody.AppendChild(new BodyProperties());

            foreach (Paragraph paragraph in textBody.Elements <Paragraph>())
            {
                ParagraphProperties  paragraphProperties  = paragraph.GetFirstChild <ParagraphProperties>() ?? paragraph.PrependChild(new ParagraphProperties());
                DefaultRunProperties defaultRunProperties = paragraphProperties.GetFirstChild <DefaultRunProperties>() ?? paragraphProperties.AppendChild(new DefaultRunProperties());
                defaultRunProperties.RemoveAllChildren <LatinFont>();
                defaultRunProperties.RemoveAllChildren <ComplexScriptFont>();

                defaultRunProperties.AppendChild(new LatinFont()
                {
                    Typeface = typeface
                });
                defaultRunProperties.AppendChild(new ComplexScriptFont()
                {
                    Typeface = typeface
                });

                foreach (Run run in paragraph.Elements <Run>())
                {
                    RunProperties runProperties = run.GetFirstChild <RunProperties>() ?? run.PrependChild(new RunProperties());
                    runProperties.RemoveAllChildren <LatinFont>();
                    runProperties.RemoveAllChildren <ComplexScriptFont>();

                    runProperties.AppendChild(new LatinFont()
                    {
                        Typeface = typeface
                    });
                    runProperties.AppendChild(new ComplexScriptFont()
                    {
                        Typeface = typeface
                    });
                }
            }

            return(this.result);
        }