internal static string GetListItemTextFormat(List list, int level) { var abstractNumElement = list.GetAbstractNum(list.NumId); //Find lvl node var lvlNodes = abstractNumElement.Descendants().Where(n => n.Name.LocalName == "lvl"); var lvlNode = lvlNodes.FirstOrDefault(n => n.GetAttribute(DocX.w + "ilvl").Equals(level.ToString())); // No ilvl, check if a numStyleLink is used. if (lvlNode == null) { var linkedStyleNumId = HelperFunctions.GetLinkedStyleNumId(list.Document, list.NumId.ToString()); if (linkedStyleNumId != -1) { abstractNumElement = list.GetAbstractNum(linkedStyleNumId); lvlNodes = abstractNumElement.Descendants().Where(n => n.Name.LocalName == "lvl"); lvlNode = lvlNodes.FirstOrDefault(n => n.GetAttribute(DocX.w + "ilvl").Equals(level.ToString())); } if (lvlNode == null) { return("%1."); } } var textFormatNode = lvlNode.Descendants().First(n => n.Name.LocalName == "lvlText"); return(textFormatNode.GetAttribute(DocX.w + "val")); }
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); }
internal static XElement GetListItemAlignment(List list, int level) { var abstractNumElement = list.GetAbstractNum(list.NumId); //Find lvl node var lvlNodes = abstractNumElement.Descendants().Where(n => n.Name.LocalName == "lvl"); var lvlNode = lvlNodes.FirstOrDefault(n => n.GetAttribute(DocX.w + "ilvl").Equals(level.ToString())); // No ilvl, check if a numStyleLink is used. if (lvlNode == null) { var linkedStyleNumId = HelperFunctions.GetLinkedStyleNumId(list.Document, list.NumId.ToString()); if (linkedStyleNumId != -1) { abstractNumElement = list.GetAbstractNum(linkedStyleNumId); lvlNodes = abstractNumElement.Descendants().Where(n => n.Name.LocalName == "lvl"); lvlNode = lvlNodes.FirstOrDefault(n => n.GetAttribute(DocX.w + "ilvl").Equals(level.ToString())); } if (lvlNode == null) { return(null); } } var pPr = lvlNode.Descendants().FirstOrDefault(n => n.Name.LocalName == "pPr"); if (pPr != null) { var ind = pPr.Descendants().FirstOrDefault(n => n.Name.LocalName == "ind"); if (ind != null) { return(ind); } } return(null); }