예제 #1
0
        private static int GetLinkedStyleNumId(DocX document, string numId)
        {
            Debug.Assert(document != null, "document should not be null");

            var abstractNumElement = HelperFunctions.GetAbstractNum(document, numId);

            if (abstractNumElement != null)
            {
                var numStyleLink = abstractNumElement.Element(XName.Get("numStyleLink", DocX.w.NamespaceName));
                if (numStyleLink != null)
                {
                    var val = numStyleLink.Attribute(XName.Get("val", DocX.w.NamespaceName));
                    if (!string.IsNullOrEmpty(val.Value))
                    {
                        var linkedStyle = HelperFunctions.GetStyle(document, val.Value);
                        if (linkedStyle != null)
                        {
                            var linkedNumId = linkedStyle.Descendants(XName.Get("numId", DocX.w.NamespaceName)).FirstOrDefault();
                            if (linkedNumId != null)
                            {
                                var linkedNumIdVal = linkedNumId.Attribute(XName.Get("val", DocX.w.NamespaceName));
                                if (!string.IsNullOrEmpty(linkedNumIdVal.Value))
                                {
                                    return(Int32.Parse(linkedNumIdVal.Value));
                                }
                            }
                        }
                    }
                }
            }

            return(-1);
        }
예제 #2
0
        internal static string GetListItemType(Paragraph p, DocX document)
        {
            var paragraphNumberPropertiesDescendants = p.ParagraphNumberProperties.Descendants();
            var ilvlNode  = paragraphNumberPropertiesDescendants.FirstOrDefault(el => el.Name.LocalName == "ilvl");
            var ilvlValue = (ilvlNode != null) ? ilvlNode.Attribute(DocX.w + "val").Value : null;

            var numIdNode  = paragraphNumberPropertiesDescendants.FirstOrDefault(el => el.Name.LocalName == "numId");
            var numIdValue = (numIdNode != null) ? numIdNode.Attribute(DocX.w + "val").Value : null;

            var abstractNumNode = HelperFunctions.GetAbstractNum(document, numIdValue);

            if (abstractNumNode != null)
            {
                // Find lvl node.
                var lvlNodes = abstractNumNode.Descendants().Where(n => n.Name.LocalName == "lvl");
                // No lvl, check if a numStyleLink is used.
                if (lvlNodes.Count() == 0)
                {
                    var linkedStyleNumId = HelperFunctions.GetLinkedStyleNumId(document, numIdValue);
                    if (linkedStyleNumId != -1)
                    {
                        abstractNumNode = HelperFunctions.GetAbstractNum(document, linkedStyleNumId.ToString());
                        if (abstractNumNode != null)
                        {
                            lvlNodes = abstractNumNode.Descendants().Where(n => n.Name.LocalName == "lvl");
                        }
                    }
                }
                XElement lvlNode = null;
                foreach (XElement node in lvlNodes)
                {
                    if (node.Attribute(DocX.w + "ilvl").Value.Equals(ilvlValue))
                    {
                        lvlNode = node;
                        break;
                    }
                    else if (ilvlValue == null)
                    {
                        var numStyleNode = node.Descendants().FirstOrDefault(n => n.Name.LocalName == "pStyle");
                        if ((numStyleNode != null) && numStyleNode.GetAttribute(DocX.w + "val").Equals(p.StyleName))
                        {
                            lvlNode = node;
                            break;
                        }
                    }
                }

                if (lvlNode != null)
                {
                    var numFmtNode = lvlNode.Descendants().First(n => n.Name.LocalName == "numFmt");
                    return(numFmtNode.Attribute(DocX.w + "val").Value);
                }
            }

            return(null);
        }
예제 #3
0
파일: List.cs 프로젝트: zhaojingbo918/DocX
 /// <summary>
 /// Get the abstractNum definition for the given numId
 /// </summary>
 /// <param name="numId">The numId on the pPr element</param>
 /// <returns>XElement representing the requested abstractNum</returns>
 internal XElement GetAbstractNum(int numId)
 {
     return(HelperFunctions.GetAbstractNum(this.Document, numId.ToString()));
 }