Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thanks for your request. Could you please provide me more information what you try to achieve? Why do you need number of merge fields in cell? As workaround you can get number of merge fields before mail merge. For example you can use the following code.
//Create hash table
Hashtable cellsHash = new Hashtable();
//Open document
Document doc = new Document(@"Test109\in.doc");
//Get collection of cells
NodeCollection cells = doc.GetChildNodes(NodeType.Cell, true);
foreach (Cell cell in cells)
{
int mergefieldsCount = 0;
// calculate count of Mergefield in the current cell
NodeCollection fieldStarts = cell.GetChildNodes(NodeType.FieldStart, true);
foreach (FieldStart start in fieldStarts)
{
if (start.FieldType == FieldType.FieldMergeField)
mergefieldsCount++;
}
//Add entry into hashtable
cellsHash.Add(cell, mergefieldsCount);
}
Then you can get count of mergefield from created hashtable. For example.
int count = Convert.ToInt32(cellsHash[cells[0]]);
Hope this helps.
Best regards.