Repacing mailmergefield by another documents


#1

Hello, it is possible using aspose.word to insert documents in a document by replacing mailmergefieds by documents.
for exemple if I’ve.




<>



I’d like to replace <> by documents .doc.

It is possible for me to store document filemane on a database table like I’ve done with Image using aspose.word.

Regards.


#2

Here are the steps to insert documents into merge fields in another document:

1. Create a document and insert merge fields into it.

2. Document.MailMerge execute will work fine as is for simple string fields.

3. Define an event handler for the MergeField event.

4. Inside your event handler, you need to load another Document. Once the document is loaded, you need to copy or move content from the resume document to your report document.

5. Moving/copying document is done section by section. See Section object methods. Also, see here:
http://www.aspose.com/forums/ShowPost.aspx?PostID=15567
Please note that some formatting (especially list formatting) might be lost when moving content from one document to another.

Refer to this thread to get more info:
http://www.aspose.com/forums/ShowPost.aspx?PostID=12733

Also, search the forum, there are many threads dedicated to this problem.


#3

Thanks. I must add that copying lists is now handled correctly and list formatting is not lost.


#4

Hello, by inserting this document (see attachement ) to another I’ve error :
Enable to read beyong the end of the stream.

Regards


#5









private void HandleMergeFieldEvent(object sender, MergeFieldEventArgs e)
{
//This creates a new document builder for every event.
//Although DocumentBuilder is a lightweight object, it still
//might be better to cache it in a field of this class.
DocumentBuilder builder = new DocumentBuilder(e.Document);

if (e.FieldName == "Description")
{
builder.MoveToMergeField(e.FieldName);
string fieldValue = e.FieldValue.ToString();

if (fieldValue.IndexOf("Blue") != -1)
builder.Font.Color = System.Drawing.Color.Blue;
else
builder.Font.Color = System.Drawing.Color.Red;

//Write the text using the builder, don't let the mail merge engine to insert text too.
builder.Write(fieldValue);
e.Text = "";
}
}










#6

Try another code to combine documents:
http://www.aspose.com/forums/ShowPost.aspx?PostID=16352