How to convert a url string to image in a table

Hi,
I’m inserting a table to a word document, as the https://forum.aspose.com/t/97128 shows, and it worked almost perfect to me. But i have a concern, my datatable is something like this…
Name_of_client | img.jpg | 1 | data
Name_of_client2 | img_2.jpg | 23 | data2
Using the numbre I have to change the color background of the cell, depending from its value,
Ex: < 10 → green, 10 to 20 yellow and 20 > red.
And from the cell img.jpg use it like url of a certain image that should be inserted insted of the text.
Any idea how can I do this?
Thank you for the atention
Ed

Hi Ed,
Thanks for your inquiry.
You can achieve this using the IFieldMergingHandler. Please see the sample code below. You set the handler before mail merge like below:

// Set up handler called whenever a merge field is about to be merged.
doc.MailMerge.FieldMergingCallback = new HandleMergeFormatting();
// Now we ca execute mail merge
doc.MailMerge.ExecuteWithRegions(data);

The FieldMerging method is called when a regular merge field is encountered during mail merge. You can set custom logic in there.
To insert an image during mail merge you need to insert a special merge field with the prefix “Image:” into your document. This is how you do it using DocumentBuilder:
When executing mail merge you use the regular field name “MyImage” and then pass a stream containing your image. When the Image:MyField merge field is encountered the ImageFieldMerging handler method is called. The image is then transferred to the mail merge engine as shown in the code. Note the overloads of the ImageFieldMergingArgs, you can set any one of these at time to merge an image during mail merge.

public class HandleMergeFormatting: IFieldMergingCallback
{
    private DocumentBuilder mBuilder;
    void IFieldMergingCallback.FieldMerging(FieldMergingArgs args)
    {
        // Check if this column is the one we are interested in
        if (args.FieldName == "Number")
        {
            // Init builder if no existing builder created.
            if (mBuilder == null)
                mBuilder = new DocumentBuilder(args.Document);
            // Pick color depending upon field value
            Color cellColor;
            int value = (int) args.FieldValue;
            if (value <10)
                cellColor = Color.Green;
            else if (value <20)
                cellColor = Color.Yellow;
            else
                cellColor = Color.Red;
            // Move to the merge field
            mBuilder.MoveToMergeField(args.FieldName, false, false);
            // Change the cell color
            mBuilder.CellFormat.Shading.BackgroundPatternColor = cellColor;
        }
    }
    void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args)
    {
        if (args.FieldName == "MyImage")
        {
            Image image = Image.FromStream((MemoryStream) args.FieldValue);
            args.Image = image;
        }
    }
}

Thanks,