@KeerthanaRamesh19 Thank you for additional information. Yes, the problem is caused by your code, which ruins node structure and as a result the fields are broken. Here is nodes structure in the header before processing with your code:
And after processing:
As you can see Run nodes that represent field code and values are moved outside the field. This causes the problem you observe.
If your goal is to make ^text
superscripted and _text
subscripted, you can easily achieve this using find/replace functionality of Aspose.Words. For example see the following code:
Dictionary<string, string> GreekSymbols = new Dictionary<string, string>()
{
{ "alpha", "α" }, { "beta", "β" }, { "gamma", "γ" }, { "delta", "δ" },
{ "epsilon", "ε" }, { "zeta", "ζ" }, { "eta", "η" }, { "theta", "θ" },
{ "iota", "ι" }, { "kappa", "κ" }, { "lambda", "λ" }, { "mu", "μ" },
{ "nu", "ν" }, { "xi", "ξ" }, { "omicron", "ο" }, { "pi", "π" },
{ "rho", "ρ" }, { "sigma", "σ" }, { "tau", "τ" }, { "upsilon", "υ" },
{ "phi", "φ" }, { "chi", "χ" }, { "psi", "ψ" }, { "omega", "ω" }
};
Document doc = new Document(@"C:\Temp\in.docx");
// Make numbers super or sub scripted.
FindReplaceOptions optSuperscript = new FindReplaceOptions();
optSuperscript.UseSubstitutions = true;
optSuperscript.ApplyFont.Superscript = true;
doc.Range.Replace(new Regex(@"\^(\d+)"), "$1", optSuperscript);
FindReplaceOptions optSubscript = new FindReplaceOptions();
optSubscript.UseSubstitutions = true;
optSubscript.ApplyFont.Subscript = true;
doc.Range.Replace(new Regex(@"_(\d+)"), "$1", optSubscript);
// Replace greek
foreach (string greek in GreekSymbols.Keys)
{
doc.Range.Replace("^" + greek, GreekSymbols[greek], optSuperscript);
doc.Range.Replace("_" + greek, GreekSymbols[greek], optSubscript);
}
doc.Save(@"C:\Temp\out.docx");