Ejemplo n.º 1
0
        public void BuildProps_Test()
        {
            var style = new WStyle
            {
                StyleParagraphProperties = new DocumentFormat.OpenXml.Wordprocessing.StyleParagraphProperties()
            };

            _instance.BuildProps(style);

            _propsFac.Received(1).Build(style.StyleParagraphProperties);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add a style into document
        /// </summary>
        /// <param name="style"></param>
        /// <param name="spart"></param>
        /// <param name="context"></param>
        public static void Render(this Style style, StyleDefinitionsPart spart, ContextModel context)
        {
            var oxstyle = new DocumentFormat.OpenXml.Wordprocessing.Style()
            {
                Type        = style.Type.ToOOxml(),
                CustomStyle = style.CustomStyle,
                StyleId     = style.StyleId,
                StyleName   = new DocumentFormat.OpenXml.Wordprocessing.StyleName()
                {
                    Val = style.StyleId
                },
                PrimaryStyle = new DocumentFormat.OpenXml.Wordprocessing.PrimaryStyle()
                {
                    Val = style.PrimaryStyle ? DocumentFormat.OpenXml.Wordprocessing.OnOffOnlyValues.On : DocumentFormat.OpenXml.Wordprocessing.OnOffOnlyValues.Off
                }
            };

            DocumentFormat.OpenXml.Wordprocessing.StyleRunProperties srp = new DocumentFormat.OpenXml.Wordprocessing.StyleRunProperties();
            if (style.Bold.HasValue && style.Bold.Value)
            {
                srp.Append(new DocumentFormat.OpenXml.Wordprocessing.Bold());
            }
            if (style.Italic.HasValue && style.Italic.Value)
            {
                srp.Append(new DocumentFormat.OpenXml.Wordprocessing.Italic());
            }
            if (!string.IsNullOrWhiteSpace(style.FontName))
            {
                srp.Append(new DocumentFormat.OpenXml.Wordprocessing.RunFonts()
                {
                    Ascii = style.FontName, HighAnsi = style.FontName, EastAsia = style.FontName, ComplexScript = style.FontName
                });
            }
            if (!string.IsNullOrWhiteSpace(style.FontSize))
            {
                srp.Append(new DocumentFormat.OpenXml.Wordprocessing.FontSize()
                {
                    Val = style.FontSize
                });
            }
            if (!string.IsNullOrWhiteSpace(style.FontColor))
            {
                srp.Append(new DocumentFormat.OpenXml.Wordprocessing.Color()
                {
                    Val = style.FontColor
                });
            }
            if (!string.IsNullOrWhiteSpace(style.Shading))
            {
                srp.Append(new DocumentFormat.OpenXml.Wordprocessing.Shading()
                {
                    Fill = style.Shading
                });
            }

            if (!string.IsNullOrWhiteSpace(style.StyleBasedOn))
            {
                oxstyle.Append(new DocumentFormat.OpenXml.Wordprocessing.BasedOn()
                {
                    Val = style.StyleBasedOn
                });
            }

            oxstyle.Append(srp);

            spart.Styles.Append(oxstyle);
        }