internal static List CreateItemInList(List list, string listText, int level = 0, ListItemType listType = ListItemType.Numbered, int?startNumber = null, bool trackChanges = false) { if (list.NumId == 0) { list.CreateNewNumberingNumId(level, listType); } if (!string.IsNullOrEmpty(listText)) { var newParagraphSection = new XElement ( XName.Get("p", DocX.w.NamespaceName), new XElement(XName.Get("pPr", DocX.w.NamespaceName), new XElement(XName.Get("numPr", DocX.w.NamespaceName), new XElement(XName.Get("ilvl", DocX.w.NamespaceName), new XAttribute(DocX.w + "val", level)), new XElement(XName.Get("numId", DocX.w.NamespaceName), new XAttribute(DocX.w + "val", list.NumId)))), new XElement(XName.Get("r", DocX.w.NamespaceName), new XElement(XName.Get("t", DocX.w.NamespaceName), listText)) ); if (trackChanges) { newParagraphSection = CreateEdit(EditType.ins, DateTime.Now, newParagraphSection); } if (startNumber == null) { list.AddItem(new Paragraph(list.Document, newParagraphSection, 0, ContainerType.Paragraph)); } else { list.AddItemWithStartValue(new Paragraph(list.Document, newParagraphSection, 0, ContainerType.Paragraph), (int)startNumber); } } return(list); }
internal static List CreateItemInList(List list, string listText, int level = 0, ListItemType listType = ListItemType.Numbered, int?startNumber = null, bool trackChanges = false, bool continueNumbering = false) { if (list.NumId == 0) { list.CreateNewNumberingNumId(level, listType, startNumber, continueNumbering); } if (listText != null) //I see no reason why you shouldn't be able to insert an empty element. It simplifies tasks such as populating an item from html. { var newParagraphSection = new XElement ( XName.Get("p", DocX.w.NamespaceName), new XElement(XName.Get("pPr", DocX.w.NamespaceName), new XElement(XName.Get("numPr", DocX.w.NamespaceName), new XElement(XName.Get("ilvl", DocX.w.NamespaceName), new XAttribute(DocX.w + "val", level)), new XElement(XName.Get("numId", DocX.w.NamespaceName), new XAttribute(DocX.w + "val", list.NumId)))), new XElement(XName.Get("r", DocX.w.NamespaceName), new XElement(XName.Get("t", DocX.w.NamespaceName), listText)) ); if (trackChanges) { newParagraphSection = CreateEdit(EditType.ins, DateTime.Now, newParagraphSection); } if (startNumber == null) { list.AddItem(new Paragraph(list.Document, newParagraphSection, 0, ContainerType.Paragraph)); } else { list.AddItemWithStartValue(new Paragraph(list.Document, newParagraphSection, 0, ContainerType.Paragraph), (int)startNumber); } } return(list); }
internal static List CreateItemInList(List list, string listText, int level = 0, ListItemType listType = ListItemType.Numbered, int?startNumber = default(int?), bool trackChanges = false, bool continueNumbering = false) { if (list.NumId == 0) { list.CreateNewNumberingNumId(level, listType, startNumber, continueNumbering); } if (listText != null) { XElement xElement = new XElement(XName.Get("p", DocX.w.NamespaceName), new XElement(XName.Get("pPr", DocX.w.NamespaceName), new XElement(XName.Get("numPr", DocX.w.NamespaceName), new XElement(XName.Get("ilvl", DocX.w.NamespaceName), new XAttribute(DocX.w + "val", level)), new XElement(XName.Get("numId", DocX.w.NamespaceName), new XAttribute(DocX.w + "val", list.NumId)))), new XElement(XName.Get("r", DocX.w.NamespaceName), new XElement(XName.Get("t", DocX.w.NamespaceName), listText))); if (trackChanges) { xElement = CreateEdit(EditType.ins, DateTime.Now, xElement); } if (!startNumber.HasValue) { list.AddItem(new Paragraph(list.Document, xElement, 0, ContainerType.Paragraph)); } else { list.AddItemWithStartValue(new Paragraph(list.Document, xElement, 0, ContainerType.Paragraph), startNumber.Value); } } return(list); }
internal static List CreateItemInList(List list, string listText, int level = 0, ListItemType listType = ListItemType.Numbered, int? startNumber = null, bool trackChanges = false) { if (list.NumId == 0) { list.CreateNewNumberingNumId(level, listType); } if (!string.IsNullOrEmpty(listText)) { var newParagraphSection = new XElement ( XName.Get("p", DocX.w.NamespaceName), new XElement(XName.Get("pPr", DocX.w.NamespaceName), new XElement(XName.Get("numPr", DocX.w.NamespaceName), new XElement(XName.Get("ilvl", DocX.w.NamespaceName), new XAttribute(DocX.w + "val", level)), new XElement(XName.Get("numId", DocX.w.NamespaceName), new XAttribute(DocX.w + "val", list.NumId)))), new XElement(XName.Get("r", DocX.w.NamespaceName), new XElement(XName.Get("t", DocX.w.NamespaceName), listText)) ); if (trackChanges) newParagraphSection = CreateEdit(EditType.ins, DateTime.Now, newParagraphSection); if (startNumber == null) { list.AddItem(new Paragraph(list.Document, newParagraphSection, 0, ContainerType.Paragraph)); } else { list.AddItemWithStartValue(new Paragraph(list.Document, newParagraphSection, 0, ContainerType.Paragraph), (int)startNumber); } } return list; }
internal static List CreateItemInList(List list, string listText, int level = 0, ListItemType listType = ListItemType.Numbered, int? startNumber = null, bool trackChanges = false, bool continueNumbering = false) { if (list.NumId == 0) { list.CreateNewNumberingNumId(level, listType, startNumber, continueNumbering); } if (listText != null) //I see no reason why you shouldn't be able to insert an empty element. It simplifies tasks such as populating an item from html. { var newParagraphSection = new XElement ( XName.Get("p", DocX.w.NamespaceName), new XElement(XName.Get("pPr", DocX.w.NamespaceName), new XElement(XName.Get("numPr", DocX.w.NamespaceName), new XElement(XName.Get("ilvl", DocX.w.NamespaceName), new XAttribute(DocX.w + "val", level)), new XElement(XName.Get("numId", DocX.w.NamespaceName), new XAttribute(DocX.w + "val", list.NumId)))), new XElement(XName.Get("r", DocX.w.NamespaceName), new XElement(XName.Get("t", DocX.w.NamespaceName), listText)) ); if (trackChanges) newParagraphSection = CreateEdit(EditType.ins, DateTime.Now, newParagraphSection); if (startNumber == null) { list.AddItem(new Paragraph(list.Document, newParagraphSection, 0, ContainerType.Paragraph)); } else { list.AddItemWithStartValue(new Paragraph(list.Document, newParagraphSection, 0, ContainerType.Paragraph), (int)startNumber); } } return list; }