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

Free Support Forum - aspose.com

Inserting one document into the middle of another document?

Is it still the case that there’s not a single function capable of inserting a document into the middle of another document? Has this been added to Aspose.Words yet, or do I still need to write code to traverse the nodes in the source document and import each one into the destination document?

What I essentially want to do is the equivalent of copying an entire source document to the clipboard, and then pasting that into an arbitrary location in the destination document.

Hi

Thanks for your request. If you just need to copy one document to another, you can use the approach suggested in the following article:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-insert-a-document-into-another-document.html

Please let me know in case of any issue, I will be glad to help you.

Best regards,

I saw that page previously, but it doesn’t account for a variety of features that a document may contain, such as source vs. destination list properties, nested lists, differing style names, etc. I assume there’s not a more full-featured code snippet somewhere? Are there any plans to add a single function to Aspose for document insertion (as opposed to appending)?

Thanks!

Hi Steve,

Thanks for your inquiry. The code in the article proposed by Andrey handles all of those things that you described for you automatically. More specifically the NodeImporter class handles this when importing a node from one document into another.

If you have any troubles, could you please attach your document here for testing? Regarding your other query, we will consider adding a built-in method to insert a document into another document.

Thanks,

See attached for sample code and three .doc files for example input/output. Notice that in the resulting .doc, the numbering is incorrect. Am I doing something wrong?

Hi there,

Thanks for attaching your documents here. I can see what you mean. Currently this is the expected behaviour as the two lists are separate so they do not run together. You can get this behaviour by setting the list to use a linked style and importing the nodes within the InsertDocument code using ImportFormatMode.UseDestinationStyles instead.

However this may not always be the desired setup, in this case you can use the code below which should work in any situation.

dstDoc.NodeChangingCallback = new HandleListsDuringImport();<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Bookmark bookmark = dstDoc.Range.Bookmarks["insertionPlace"];

InsertDocument(bookmark.BookmarkStart.ParentNode, srcDoc);

public class HandleListsDuringImport : INodeChangingCallback

{

public void NodeInserted(NodeChangingArgs args)

{

// Check if the node inserted is a paragraph with a list and the same with the previous sibling as well.

if (args.Node.NodeType == NodeType.Paragraph)

{

Paragraph para = (Paragraph)args.Node;

if(para.PreviousSibling != null && para.PreviousSibling.NodeType == NodeType.Paragraph)

{

Paragraph prevPara = (Paragraph)para.PreviousSibling;

if (para.IsListItem && prevPara.IsListItem)

{

// Make the inserted content use the same list as the previous paragraph.

para.ListFormat.List = prevPara.ListFormat.List;

}

}

}

}

public void NodeInserting(NodeChangingArgs args)

{

// Do Nothing

}

public void NodeRemoved(NodeChangingArgs args)

{

// Do Nothing

}

public void NodeRemoving(NodeChangingArgs args)

{

// Do Nothing

}

}

Thanks,

The issues you have found earlier (filed as WORDSNET-5251) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(13)