I would like to do the following with a list, either one of the two:
First, I have an existing document with a numbered list, such as:
1 First Item
2 Second Item
3 Third Item
I would like to insert some items in between the second list, like so:
1 First Item
2 Second Item
2.1 Second first point item
2.2 Second second point item
3 Third Item
When I do this, however, using NodeImporter (the new items come from another document), I get:
1 First Item
2 Second Item
1.1 Second first point item
1.2 Second second point item
3 Third Item
Which is close, but not quite. How can I set either the starting value of the middle list, or better yet, “connect” it to the list itself so the numbers order automatically?
I would like to insert some items in between the second list, like so:
1 First Item 2 Second Item 2.1 Second first point item 2.2 Second second point item 3 Third Item
Please use the following code snippet to achieve your requirements. Hope this helps you. I have attached the input/output documents with this post for your kind reference.
Document doc = new Document(MyDir + "Test52.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 1, true);
if (para.ListFormat.IsListItem)
{
builder.ListFormat.List = para.ListFormat.List;
builder.MoveTo(para);
builder.Writeln("");
// Completely customize yet another list level.
ListLevel level2 = builder.ListFormat.List.ListLevels[1];
level2.NumberStyle = NumberStyle.Arabic;
level2.NumberFormat = "\x0000.\x0001";
builder.ListFormat.ListIndent();
builder.Writeln("Second first point item");
builder.Write("Second point item");
}
doc.Save(MyDir + "Out.docx");
mrjama:
When I do this, however, using NodeImporter (the new items come from another document), I get:
1 First Item 2 Second Item 1.1 Second first point item 1.2 Second second point item 3 Third Item
Which is close, but not quite. How can I set either the starting value of the middle list, or better yet, “connect” it to the list itself so the numbers order automatically?
In your case, I suggest you please check the ListLevel.NumberFormat, ListLevel.NumberStyle and ListLevel.StartAt properties. It would be great if you please share your input/output documents along with expected output document here. We will investigate, how you want your final Word output be generated like. We will then provide you more information on this along with code.
mrjama:
One additional note. Setting StartAt property for the paragraph sets the second number in the label, not the first. So, for example:
new_para.ListFormat.ListLevel.StartAt = 99;
Please note that Aspose.Words mimics the same behavior as MS Word do. If you do the same by using MS Word, you will get the same output. In this case, I suggest you please set the ListLevel.NumberFormat and set ListLevel.StartAt property according to your requirements.
Rather than use the “ListLevel.StartAt” property, which appears to always adjust the LAST number/letter in the label, you can adjust the value of the list itself using the method above, referencing each field using an index into the array.
This may not work for every scenario, as I created a separate list that is not “connected” to the higher level list. I could never get my new list items to “connect” to the parent list. I may keep investigating.
However, it is quite simple to create a brand new list, manually set where you want the numbering to start, and go from there. So, I solved the problem with two lists instead of one. Not the best but it works. Thanks.
Thanks for your feedback. It is nice to hear from you that you have solved your problem. I am checking with this scenario and will get back to you soon with further detail.
Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.
Thanks for your patience. I have logged a new feature request as WORDSNET-9007 in our issue tracking system to support the ListLevel.StartAt for number formats like 1.3, 4.5 etc. You will be notified via this forum thread once this feature is available.
Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.