当前位置: 首页>>代码示例>>C#>>正文


C# Style.AppendChild方法代码示例

本文整理汇总了C#中Style.AppendChild方法的典型用法代码示例。如果您正苦于以下问题:C# Style.AppendChild方法的具体用法?C# Style.AppendChild怎么用?C# Style.AppendChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Style的用法示例。


在下文中一共展示了Style.AppendChild方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateStyle

        /// <summary>
        /// Creates a style.
        /// </summary>
        /// <param name="ps">The paragraph style.</param>
        /// <param name="styleId">The style id.</param>
        /// <param name="styleName">The style name.</param>
        /// <param name="basedOnStyleId">The based on style id.</param>
        /// <param name="nextStyleId">The next style id.</param>
        /// <param name="isDefault"><c>true</c> if the style is default.</param>
        /// <param name="isCustomStyle"><c>true</c> if the style is a custom style.</param>
        /// <returns>The <see cref="Style" />.</returns>
        private static Style CreateStyle(
            ParagraphStyle ps,
            string styleId,
            string styleName,
            string basedOnStyleId,
            string nextStyleId,
            bool isDefault = false,
            bool isCustomStyle = true)
        {
            // todo: add font to FontTable?
            var rPr = new StyleRunProperties();

            // http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.color.aspx
            var color = new Color { Val = ps.TextColor.ToString().Trim('#').Substring(2) };
            rPr.AppendChild(color);

            // http://msdn.microsoft.com/en-us/library/cc850848.aspx
            rPr.AppendChild(new RunFonts { Ascii = ps.FontFamily, HighAnsi = ps.FontFamily });
            rPr.AppendChild(new FontSize { Val = new StringValue((ps.FontSize * 2).ToString(CultureInfo.InvariantCulture)) });
            rPr.AppendChild(
                new FontSizeComplexScript
                    {
                        Val = new StringValue((ps.FontSize * 2).ToString(CultureInfo.InvariantCulture))
                    });

            if (ps.Bold)
            {
                rPr.AppendChild(new Bold());
            }

            if (ps.Italic)
            {
                rPr.AppendChild(new Italic());
            }

            var pPr = new StyleParagraphProperties();
            var spacingBetweenLines2 = new SpacingBetweenLines
                {
                    After = string.Format(CultureInfo.InvariantCulture, "{0}", ps.SpacingAfter * 20),
                    Before = string.Format(CultureInfo.InvariantCulture, "{0}", ps.SpacingBefore * 20),
                    Line = string.Format(CultureInfo.InvariantCulture, "{0}", ps.LineSpacing * 240),
                    LineRule = LineSpacingRuleValues.Auto
                };
            var indentation = new Indentation
                {
                    Left = string.Format(CultureInfo.InvariantCulture, "{0}", ps.LeftIndentation * 20),
                    Right = string.Format(CultureInfo.InvariantCulture, "{0}", ps.RightIndentation * 20)
                };
            var contextualSpacing1 = new ContextualSpacing();

            pPr.AppendChild(spacingBetweenLines2);
            pPr.AppendChild(contextualSpacing1);
            pPr.AppendChild(indentation);

            // StyleRunProperties styleRunProperties7 = new StyleRunProperties();
            // RunFonts runFonts8 = new RunFonts() { Ascii = "Verdana", HighAnsi = "Verdana" };
            // Color color7 = new Color() { Val = "000000" };

            // styleRunProperties7.AppendChild(runFonts8);
            // styleRunProperties7.AppendChild(color7);

            // http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.style.aspx
            var style = new Style
                {
                    Default = new OnOffValue(isDefault),
                    CustomStyle = new OnOffValue(isCustomStyle),
                    StyleId = styleId,
                    Type = StyleValues.Paragraph
                };

            style.AppendChild(new Name { Val = styleName });
            if (basedOnStyleId != null)
            {
                style.AppendChild(new BasedOn { Val = basedOnStyleId });
            }

            //// var rsid = new Rsid();

            // style.AppendChild(rsid);
            var primaryStyle = new PrimaryStyle();
            style.AppendChild(primaryStyle);
            if (nextStyleId != null)
            {
                style.AppendChild(new NextParagraphStyle { Val = nextStyleId });
            }

            style.AppendChild(rPr);
            style.AppendChild(pPr);
            return style;
//.........这里部分代码省略.........
开发者ID:benjaminrupp,项目名称:oxyplot,代码行数:101,代码来源:WordDocumentReportWriter.cs


注:本文中的Style.AppendChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。