We're sorry Aspose doesn't work properply without JavaScript enabled.

# Restart numbering when using NodeImporter

Hello
I am importing nodes into an existing Word doc using NodeImporter and would like to restart numbering in the final doc for some of the imported nodes which have a ListItem.
How to do that?
Thanks,
Roger

Hi

Thanks for your inquiry. If you need to reset numbering in list you should reset list. For example document contains 10 items of the same list. We need to reset numbering from 5th element. Here is code:

//Open document
Document doc = new Document(@"Test193\in.doc");
//The document contains 10 paragraphs (list items)
//Get first paragraph (first list item)
Paragraph firstItem = doc.FirstSection.Body.FirstParagraph;
//Create copy of list
//Get 5th element
Paragraph item = doc.FirstSection.Body.Paragraphs[4];
while (item.IsListItem)
{
item.ListFormat.List = listCopy;
item = item.NextSibling as Paragraph;
if (item == null)
break;
}
//save output document
doc.Save(@"Test193\out.doc");


Documents are attached. Hope this could help you to achieve what you need
Best regards.

To make it more clear here some code:

// Loop through all sections in the source document.
foreach (Section srcSection in srcDoc.Sections)
{
// Loop through all block level nodes (paragraphs and tables) in the body of the section.
foreach (Node srcNode in srcSection.Body)
{
Paragraph para = srcNode as Paragraph;
// This creates a clone of the node, suitable for insertion into the destination document.
Node newNode = importer.ImportNode(srcNode, true);
// Check, if paragraph is ListItem and numbering should be started at 1
if ((para != null) && para.ParagraphFormat.IsListItem && para.Range.Bookmarks.Count > 0)
{
foreach (Bookmark bookmark in para.Range.Bookmarks)
{
if (bookmark.Name.StartsWith("StartNumbering"))
{
// TODO: Start renumbering
// Do something with ((Paragraph)newNode).ListFormat?

break;
}
}
}
// Insert new node after the reference node.
dstStory.InsertAfter(newNode, insertAfterNode);
insertAfterNode = newNode;
}
}


I also tried to add some section breaks etc. in base document, but numbering is always continueing from previous.
Is there any possibility to restart numbering by API of Aspose.Words when importing nodes or by adding some special formattings in base document itself (location before corresponding node gets imported).
Thanks,
Roger

Hi
I think there is the issue that at time of importing the nodes/list items, these could get inserted into an already existing list.
How is Aspose.Words handling that? Are the new list items integrated into the already existing list? Then your logic would have to be run after all nodes have been imported (finding corresponding bookmarks first). Is this the right approach of doing it?
Roger

Hi
Thank you for additional information. I think the following code could help you to achieve what you need.

Document dstDoc = new Document(@"Test196\dst.doc");
Document srcDoc = new Document(@"Test196\src.doc");
Node insertAfterNode = dstDoc.LastSection.Body.LastChild;
CompositeNode dstStory = insertAfterNode.ParentNode;
//Declare temporary list
List tmpList = null;
//Create one more temporary list
//that is needed to detect whether new list is started in the source document
List srcList = null;
// Loop through all sections in the source document.
foreach (Section srcSection in srcDoc.Sections)
{
// Loop through all block level nodes (paragraphs and tables) in the body of the section.
foreach (Node srcNode in srcSection.Body)
{
Paragraph para = srcNode as Paragraph;
// This creates a clone of the node, suitable for insertion into the destination document.
Node newNode = dstDoc.ImportNode(srcNode, true);
// Check, if paragraph is ListItem and numbering should be started at 1
if ((para != null) && para.ParagraphFormat.IsListItem)
{
bool isNewList = false;
if (!para.ListFormat.List.Equals(srcList))
{
srcList = para.ListFormat.List;
isNewList = true;
}
foreach (Bookmark bookmark in para.Range.Bookmarks)
{
if (bookmark.Name.StartsWith("StartNumbering"))
{
// TODO: Start renumbering
// Do something with ((Paragraph)newNode).ListFormat?
break;
}
}
if (tmpList == null || isNewList)
{
tmpList = (newNode as Paragraph).ListFormat.List;
}
//Set list
(newNode as Paragraph).ListFormat.List = tmpList;
}
// Insert new node after the reference node.
dstStory.InsertAfter(newNode, insertAfterNode);
insertAfterNode = newNode;
}
}
dstDoc.Save(@"Test196\out.doc");


Best regards.

Hi all
I found an easy solution for all my numbering issues when importing nodes (this issue was even more complicated when rendering to PDF using Apose.Pdf - the numbers you see in Word is not what you get in resulting PDF!):
Each section which needs continous numbering (and always starting from 1) is using an own, section-wide style for its headers with same formatting. By this way there is no messing around with internal list IDs (or whatever) when importing additional nodes.
It has just to be made sure that headers of imported content is using same header style (e.g. Heading 1, 2, 3, etc.) as the destination list, and ImportFormatMode of NodeImporter should be UseDestinationStyles.
Cheers,
Roger

It is our intention to download the service tree via ovpmutil as well as all nodes and node groups. At this point we update the file containing the node group configurations and replace some of the place holder nodes with servers that are representative of the particular service in our development environments.

Sally
Sunshine Coast