Hi there,
Sorry for late response. Have you figured out the solution?
I wrote some simple code here:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using DocumentFormat.OpenXml.Wordprocessing;using DocumentFormat.OpenXml.Packaging;using DocumentFormat.OpenXml;
namespace AppendNumberedParagraphs{ class Program { static void Main(string[] args) { using (WordprocessingDocument document = WordprocessingDocument.Open("test.docx", true)) { Paragraph p = document.MainDocumentPart.Document.Body.Elements<Paragraph>().Last();
// Create a new list paragraph, Paragraph newParagraph = new Paragraph( new ParagraphProperties( new ParagraphStyleId() { Val = "ListParagraph" }, new NumberingProperties( new NumberingLevelReference() { Val = 0 }, new NumberingId() { Val = 1 })), new Run( new Text("append text")));
// Insert the new pargraph at the end of the document. document.MainDocumentPart.Document.Body.InsertAfter<Paragraph>(newParagraph, p);
// Save changes. document.MainDocumentPart.Document.Save(); } } }}
I'm not very clear why you want to get the index. In my code, you just need to get the last paragraph, then append the new paragraph after it.
Hope it helps.
I think you can read the attributes of element "w:numPr" to distinguish them.