Free Support Forum - aspose.com

Copy Range & Images

Hi,
We are using Server side Document Generation. We found Aspose.Word might be useful to us.

Due to high problems and low time, we are moveing Word 2000 DCOM to .NET component for Word automation.

I tried to search for code to accomplish my requirement. Can you please send me code (or links) for following:

1. Copy Some range (with styles/bullets/images) of document & paste after that range immediately.
e.g. I have following text in document:
Line1
Line 2
RangeStart
Line4
Some Picture
RangeEND
Line 7

This should be :
Line1
Line 2
RangeStart
Line4
Some Picture
RangeEND
RangeStart
Line4
Some Picture
RangeEND
Line 7

2. Copy above mentioned range from another document. That reference document may contain other unwanted text. I want to copy specific range only.

3. Find & Select. I found one sample code in forum for this. But that uses range.text property to get string & then looks for desired text inside that string. However the performance will down if we follow in login in case of >1000 pages document. Code for Selecting range is not found.

Also look this forum : http://forums.asp.net/p/1135481/1838640.aspx

Please note that we are short of time and if we found Aspose useful, we will immediatly think to buy this.

Thank you,
Hemant Chandurkar
Technical Architect

Hi

Thanks for your request. I think that you can use Document.Range.Replace() method to find specified text in document and then insert section from another document. A think that the following links will help you.
http://www.aspose.com/Products/Aspose.Words/Api/FindandReplace.html
http://www.aspose.com/Products/Aspose.Words/Api/InsertOneDocumentintoAnotheratAnyLocation.html
http://www.aspose.com/Products/Aspose.Words/Api/ReplaceTextinaDocumentwithanotherDocument.html


Also see you should use Importer class to import nodes from one document to another. See the following links.
http://www.aspose.com/Products/Aspose.Words/Api/CopyingSectionsbetweenDocuments.html
http://www.aspose.com/Products/Aspose.Words/Api/Aspose.Words.NodeImporter.html

Best regards.

Hi,
Thanks for reply.
But this does not solve my problem. I want to select some range in the document and copy into other document.
Import node will copy only one paragraph.

Hi

Also you can copy any nodes from one document to another. See document model for more information.
http://www.aspose.com/Products/Aspose.Words/Api/NodeClasses.html

You can try to find all nodes that you want to copy and then insert these nodes into another document.

Best regards.

Hi,
I am trying this:

Dim nd1, nd2 As Node
nd1 = doc.SelectSingleNode("//Run[1]").Clone(True)
nd2 = doc.SelectSingleNode("//Paragraph[2]")

doc.InsertAfter(nd1, nd2)

It is throwing exception.

Hi

I think that you want to add run to paragraph. Here is C# code to achieve this.

Node nd1 = doc.SelectSingleNode("//Run[1]").Clone(true);

Node nd2 = doc.SelectSingleNode("//Paragraph[2]");

(nd2 as Paragraph).AppendChild(nd1);

I hope that it will help you.

Best regards.