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


C# ParagraphProperties.Descendants方法代码示例

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


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

示例1: AddFormatParagraph

        /// <summary>
        /// Add format paragraph
        /// </summary>
        /// <param name="paragraphProperties"></param>
        /// <returns></returns>
        private string AddFormatParagraph(ParagraphProperties paragraphProperties)
        {
            List<string> cssStyleElements = new List<string>();

            string paragraphStyle = "";
         
            if (paragraphProperties != null)
            {
                ParagraphStyleId paragraphStyleId = paragraphProperties.Descendants<ParagraphStyleId>().FirstOrDefault();
                
                if (paragraphStyleId != null)
                    paragraphStyle = paragraphStyleId.Val;
            }

            paragraphStyle = "\"" + paragraphStyle + "\"";

           
            Indentation indentation = paragraphProperties.Indentation;

            /*
            if (indentation != null)
            {
                if (indentation.Left != null)
                    cssStyleElements.Add(string.Format("margin-left:{0}pt", ConvertDxaToPoint(indentation.Left.Value)));
                else if (indentation.FirstLine != null)
                    //cssStyleElements.Add(string.Format("text-indent:{0}pt", ConvertDxaToPoint(indentation.FirstLine.Value)));
                    cssStyleElements.Add(string.Format("margin-left:{0}pt", ConvertDxaToPoint(indentation.FirstLine.Value)));
            }*/

            NumberingProperties numberingProperties = paragraphProperties.NumberingProperties;

            if (numberingProperties != null && numberingProperties.NumberingLevelReference != null && numberingProperties.NumberingId != null)
            {
                int level = numberingProperties.NumberingLevelReference.Val.Value;
                int numId = numberingProperties.NumberingId.Val.Value;

                int abstractNumId = document.MainDocumentPart.NumberingDefinitionsPart.Numbering.Descendants<NumberingInstance>().Where(x => x.NumberID == numId).FirstOrDefault().AbstractNumId.Val.Value;
                indentation = document.MainDocumentPart.NumberingDefinitionsPart.Numbering.Descendants<AbstractNum>().Where(x => x.AbstractNumberId == abstractNumId).FirstOrDefault().Descendants<Level>().Where(x => x.LevelIndex.Value == level).FirstOrDefault().Descendants<Indentation>().FirstOrDefault();
               
                Level numberingLevel = document.MainDocumentPart.NumberingDefinitionsPart.Numbering.Descendants<AbstractNum>().Where(x => x.AbstractNumberId == abstractNumId).FirstOrDefault().Descendants<Level>().Where(x => x.LevelIndex.Value == level).FirstOrDefault();
               
                if (numberingLevel.LevelText.Val.Value.Contains("%"))
                    cssStyleElements.Add(string.Format("mso-list:l{0} level{1} ol", numId, level + 1));
                else
                    cssStyleElements.Add(string.Format("mso-list:l{0} level{1} ul", numId, level + 1));
            }

            string result = "";

            foreach (string element in cssStyleElements)
                result += element + ";";

            if (result != "")
                result = paragraphStyle + string.Format(" style='{0}'", result);
            else
                result = paragraphStyle;

            return result.Trim();
        }
开发者ID:nkravch,项目名称:SALMA-2.0,代码行数:64,代码来源:DocxToHtml.cs


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