Hey,
I have a word document that is going to be translaed for several languages.
The document consists of MergeField and regular strings. All the strings are going to be translated.
Our translation guys are working with XML files (Resx).
We wrote a C# program that replaces the place holders with the relevant strings that are taken from the XML.
In some cases the block of text that should be inserted should contain also MergeFields.
What I’m doing in order to insert the MergeFields into the block of text is as following:
//Replace the key (place holder) with the Value (block of text).
doc.Range.Replace(key, value, false, true);
Document mergeFieldDoc = new Document();
DocumentBuilder builder = new DocumentBuilder(mergeFieldDoc);
string fieldName = "MyMergeField";
builder.InsertField(string.Format(@"MERGEFIELD {0} \* MERGEFORMAT", fieldName), string.Format(@"«MergeField:{0}»", fieldName));
//calling the following method that was found in the Aspose.Help.CHM file
//All the other method from the CHM were copied also....
//What I want to do here is to replace the fieldKey from the 'doc' document with the content of the created mergeFieldDoc
ReplaceTextWithDoc(doc, mergeFieldDoc, fieldKey);
That is my problem:
the ReplaceTextWithDoc method calls InsertDocEvaluator which should do the replacement
but it replaces all the block that contains the text to be replaced and not only the fieldKey string.
private ReplaceAction InsertDocEvaluator(object sender, ReplaceEvaluatorArgs e)
{
Paragraph para = (Paragraph)e.MatchNode.ParentNode;
// Insert document after the paragraph, containing match text.
InsertDocument(para, insertDoc);
// Remove the paragraph with the match text.
//para.Remove();
return (ReplaceAction.Replace);
}
Regards
Dan Oren
AppScan Development team
IBM R&D labs, Israel
Office: +972-9-9586077 ext.238
Cell: +972-52-3416300