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

Free Support Forum - aspose.com

Is it possible to copy set of nodes at one time

Hi,

I need to copy some portion of data from one document into another document with same format. So instead of looping continuous nodes(sections/paragraphs), Is there any way to select nodes from here to here and copy them into another document.

Ex: Right now I am copying some portion of data into another document like this:

while ((tempChild.NodeType == NodeType.Paragraph) || (tempChild.NodeType == NodeType.Table))
{
if (tempChild.NodeType == NodeType.Paragraph)
{
Node dstNode = subDoc.ImportNode(tempChild, true, ImportFormatMode.KeepSourceFormatting);
subDoc.FirstSection.Body.AppendChild(dstNode);
}
}

This importing individual nodes to other docs was working fine for me. But i was loosing format if the paragraphs are under List format (bulleted/numbered/…).

Is there any other way to select from this paragraph node to that paragraph node and importing all at once to other docs? then I can avoid the formatting issue if paragraphs having Listed format.

Please help me on this.

Thanks,


Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. You lost list formatting of paragraphs because you are using Document.ImportNode method. You need to use NodeImporter, in this case list formatting will be preserved. Please follow the link for more information:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.nodeimporter.html

Also, please see the following code example:

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

Best regards.

Hi Alexey,

Thanks for your response. I can use the InsertDocument() method to insert the whole source document after the particular node in target document.

But I don’t want to insert whole source document into target document. I need to select some portion of the data in source document and kept into target document.

My source document like this:

1<span style=“font-family: “Times New Roman”; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;”>
Base View

The base view of a Data loads all visits for every subject that has been reported by the Stations. The following actions are performed each time:

  • Check for files
  • Check for any filter
  • Setup
  • Generate
  • Generate list
  • Run the main session

2 Data Import

Data is delivered by the study laptops to crsreports/study_name/reports. Data is archived to crsreports/study_name/reports_archive

"study_name" is defined under the [studyshorts] section of the ini file for the given study in the config directory.

Executing an import parses the .csv files into arrays, and inserts the data into the database. Order and structure of data in csv file:

  1. scores
    1. Rater Station session_id
    2. Scale ID
    3. Item
    4. Score
    5. Datestamp
    6. Rater First Name
    7. Rater Last Name
    8. Rater ID
  2. answers
    1. Rater Station session_id
    2. Scale ID
    3. Question ID
    4. Answer String
    5. Datestamp

Let the above information is in Source document( in.doc). Now I want to create Out1.doc with Green color text and Out2.doc with Red color text with same list format.

Please let me know how can I achieve this?

Thanks,

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks you for additional information. I suggested to take a look at InsertDocuemnt example, because it shows how you should use NodeImported to import nodes from one document to another. So, please try using NodeImporter class instead of Document.ImportNode method as I suggested earlier.

Best regards.

Hi Alexey,

Thanks for your response. I tried using NodeImporter class, and getting an error like 'Cannot insert a node of this type at this location.'

Document import = new Document(@“D:\1.doc”);
Document subDoc = new Document();
CompositeNode dstStory = subDoc.FirstSection.Body.FirstParagraph.ParentNode;
foreach (Node para in import.GetChildNodes(NodeType.Paragraph, true).ToArray())
{
if (((Paragraph)para).ParagraphFormat.StyleIdentifier != StyleIdentifier.Heading1)
{
NodeImporter importer = new NodeImporter(para.Document, subDoc, ImportFormatMode.KeepSourceFormatting);
Node newNode = importer.ImportNode(para.Document.FirstChild, true);
dstStory.InsertAfter(newNode, (Node)subDoc.FirstSection.Body.FirstParagraph); // error here
}
}

1.doc having my previous post data. And here i was trying to insert all the paragraphs into another document (subDoc) with same source formatting. Is this correct way touse NodeImporter class?

Thanks,
Srinvias

Hi Srinu,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. No, it is incorrect way of using NodeImporter. You do not need to create a separate instance of NodeImporter each time when you need to import note. You should create one instance of NodeImporter and use it to import all nodes, which you need to import.

Your code should look like this (just like in InsertDocument method):

NodeImporter importer = new NodeImporter(srcDoc, subDoc, ImportFormatMode.KeepSourceFormatting);

while ((tempChild.NodeType == NodeType.Paragraph) || (tempChild.NodeType == NodeType.Table))

{

if (tempChild.NodeType == NodeType.Paragraph)

{

Node dstNode = importer.ImportNode(tempChild, true);

subDoc.FirstSection.Body.AppendChild(dstNode);

}

}

Best regards,