How do I Append One Document to Another document?
(Views :1643)

DocIO provide the support for importing one document into another document using two ways. One is by directly importing the content using ImportContent() method. Another one is by appending ole object to import the content. The following code snippet illustrates how to import one document into another document.

 

 

C#

//Directly importing the content of one document into another document

 

//Open the source document

WordDocument sourceDocument = new WordDocument("Essential DocIO.doc");

//Open the destination document

WordDocument destDocument = new WordDocument("Essential PDF.doc");

//Imports the content of source document into destination document

destDocument.ImportContent(sourceDocument, true);

//Save the destination document

 destDocument.Save("Sample.doc");

 

 

//Importing the content as OLE object into the another document

 

//opens the document

WordDocument document = new WordDocument("Essential PDF.doc");

document.LastSection.AddParagraph();

document.LastSection.AddParagraph();

document.LastParagraph.AppendText("Essential DocIO.doc has been inserted as OLE Object");

document.LastSection.AddParagraph();

//Loads the picture (for OLE Object)

WPicture pic = new WPicture(document);

pic.LoadImage(System.Drawing.Image.FromFile("DocIO.jpg"));

//Appending the document as OLE Object into another document

WOleObject oleObject = document.LastParagraph.AppendOleObject("Essential DocIO.doc", pic, OleObjectType.Word_97_2003_Document);

oleObject.DisplayAsIcon = true;

//Save the document

document.Save("Sample.doc");

 

VB

 

'Directly importing the content of one document into another document

 

'Open the source document

Dim sourceDocument As New WordDocument("Essential DocIO.doc")

'Open the destination document

Dim destDocument As New WordDocument("Essential PDF.doc")

'Imports the content of source document into destination document

destDocument.ImportContent(sourceDocument, True)

'Save the destination document

destDocument.Save("Sample.doc")

 

'Importing the content as OLE object into the another document

 

'opens the document

Dim document As New WordDocument("Essential PDF.doc")

document.LastSection.AddParagraph()

document.LastSection.AddParagraph()

document.LastParagraph.AppendText("Essential DocIO.doc has been inserted as OLE Object")

document.LastSection.AddParagraph()

'Loads the picture (for OLE Object)

Dim pic As New WPicture(document)

pic.LoadImage(System.Drawing.Image.FromFile("DocIO.jpg"))

'Appending the document as OLE Object into another document

Dim oleObject As WOleObject = document.LastParagraph.AppendOleObject("Essential DocIO.doc", pic, OleObjectType.Word_97_2003_Document)

oleObject.DisplayAsIcon = True

'Save the document

document.Save("Sample.doc")

 

 

The following sample illustrates the above code

http://help.syncfusion.com/samples/DocIO.Web/DocIOWebSamples/ImportDocument/main.htm

 

 

 

::adCenter::