Hi Team,
I am using Aspose to remove the autodate field from my word document while leaving the date in place. This seems to work perfectly for me except when the AutoDate field is found in a table. When the code finds the Autodate field in a table it removes the autodate function but does not leave the date. Is there a way of Leaving\Adding the AutoDate text to the table.
Thanks in advance
Garry
Sample Code
foreach (FieldStart start in starts)
{
if (start.FieldType == FieldType.FieldDate)
{
Node node = start;
string fieldCode = "";
while (node.NodeType != NodeType.FieldEnd)
{
if (node.NodeType == NodeType.Run)
{
fieldCode += ((Run)node).GetText();
}
node = node.NextSibling;
}
dateFieldSeparators.Add(node);
node = node.NextSibling;
Match match = Regex.Match(fieldCode, @".*?\@\s*""(?.*?)""");
dateFormat = match.Groups["dateformat"].Value;
date = DateTime.UtcNow.ToString(dateFormat, CultureInfo.CurrentCulture);
dates.Add(date);
}
if (start.FieldType == FieldType.FieldDate || start.FieldType == FieldType.FieldTime)
{
dateStarts.Add(start);
// Move cursor to the field start position
builder.MoveTo(start);
// Insert [AutoDate] text
builder.Write(date);
}
}
// Now we should remove Date and Time fields
foreach (FieldStart start in dateStarts)
{
Node currentNode = start;
while (currentNode.NodeType != NodeType.FieldEnd)
{
currentNode = currentNode.NextSibling;
currentNode.PreviousSibling.Remove();
}
currentNode.Remove();
}