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

Free Support Forum - aspose.com

Does Aspose.Words support DDE Fields

Does Aspose.Words support words DDE fields, that is can you update them and or insert them into a document ?

Hi Darel,

Thanks for considering Aspose.

Do you mean setting the DDE connection for mail merge? If this is correct, please see the properties in the Document.MailMergeSettings class which allow you to define these settings.

If this is not what you are looking for, could you please attach an example template here and we will take a look into for you.

Thanks,

I don't believe that Mail merge is what I'm talking about.

The DDE that I'm refering to is between two applications one being the dde server and the other (word document) being the client. In word the field is comprised of three parts followed by formating such as

{DDE IMPACT VbToWord Brlgl\* charformat \t}

In the above the DDE Server application is an applciation called Impact, the DDE source is VbToWord and the DDE Field is Brlgl.

I have attached a sample document that contains several DDE fields.

Hi Darel,

Thanks for attaching your template here.

I'm afraid these fields are not supported by Aspose.Words. You are unable to update these fields, but you may still be able to insert them using the DocumentBuilder.InsertField method.

Unfortunately, this field will most likely not be supported in the future as it appears to be undocumented and is not used very often (you appear to be only the second person to ask about this field).

Depending upon what object you are commicating with, you may be able to replace the DDE field functionality with internal code and field maniplications instead. If you need any help with this, please feel free to ask.

Thanks,

Adam,

Thank you for the quick response....

Is there a way to locate the field (I see that there is a FieldType.FieldDDE, just not sure how to use it), and then replace the text or what word calls the result with the new or updated content?

OR is there a way to replace the DDE Field, say with a mail merge field and then have it update?

Thanks,


Hi Darel,

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

Thanks for your inquiry. I think, you can try using the same technique as described in the following article to achieve what you need:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-rename-merge-fields.html

Hope this helps.

Best regards,

Hi Darel,

Thanks for your inquiry.

Yes both options are possible, as Alexey has suggested, that code can help. If you describe what you are looking to achievei n full we will be happy to give you some further, more specific advise.

Thanks,

Adam,

Basically what I'm trying to do is be able to update the dde fields in a document so that they reflect the current values so that the document can be printed or emailed. Currently we use office automation to have word udpate the fields using it's update fields command, but we want to move away from having to involve word and office automation for this task.

I have access to the data (current values for the dde fields) so the data is not an issue, it's just getting the document updated with it that is proving to be an issue.

Any advice or direction is greatly appreciated.

Thanks,

Hi Darel,

Thanks for this additonal information.

Sure, what applications are you populating this data from? i.e what program is the DDE fields linking to? Once we establish that we can provide some further suggestions.

Thanks,

Adam,

The application is ours, the data is being provided via the DDE link, however we can change the application to deliver the data in any manner needed.

Thanks,

Hi Darel,

Thanks for this additional information.

That's great. In that case it would be easiest to merge the data from your application into the documents using mail merge. Please see the articles here which detail mail merge. I suggest populating the data into a DataSet and merging using that.

To convert all DDE fields to Merge fields in the document, please use the code below.

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

Document doc = new Document("00000001.doc");

// Create a new builder and use it to replace fields with merge fields.

DocumentBuilder builder = new DocumentBuilder(doc);

// Search through all FieldStarts in the document

foreach (FieldStart start in doc.GetChildNodes(NodeType.FieldStart, true).ToArray())

{

// We are only interested in the DDE fields

if (start.FieldType == FieldType.FieldDDE)

{

// Get the field code

string fieldCode = GetFieldCode(start);

// Split each part using a space delimiter. Remove empty entries to ignore the first spaces in the field code.

string[] codeParts = fieldCode.Split(new string[] { " "}, StringSplitOptions.RemoveEmptyEntries);

// The field name can be found as the fourth split string.

// If the field names have spaces this part will need some extra work.

string fieldName = codeParts[3];

// Move the builder to start of the field

builder.MoveTo(start);

// Insert a new merge field using the gathered information from the original. The builder will insert this just before

// the original field.

builder.InsertField(string.Format(@"MERGEFIELD {0} \* MERGEFORMAT", fieldName));

// Remove the original field from the document.

RemoveField(start);

}

}

private static string GetFieldCode(Aspose.Words.Fields.FieldStart fieldStart)

{

StringBuilder builder = new StringBuilder();

for (Node node = fieldStart; node != null && node.NodeType != NodeType.FieldSeparator && node.NodeType != NodeType.FieldEnd; node = node.NextPreOrder(node.Document))

{

// Use the text only of Run nodes to avoid duplication.

if (node.NodeType == NodeType.Run)

builder.Append(node.GetText());

}

return builder.ToString();

}

private static void RemoveField(FieldStart fieldStart)

{

Node node = fieldStart;

bool isRemoving = true;

while (node != null && isRemoving)

{

if (node.NodeType == NodeType.FieldEnd)

isRemoving = false;

Node nextNode = node.NextPreOrder(node.Document);

node.Remove();

node = nextNode;

}

}

If you have any further queries, please feel free to ask.

Thanks,