Free Support Forum - aspose.com

Font Size of 8 is set by Aspose on Text Replace

Hello Aspose Support

I’m having an issue using Aspose Word causing the change in Font size when a text is replaced in the word document and saved in a new file. I compare the document.xml extracted from the word document and see an extra tag

<w:sz w:val=“16” />

is added by the Aspose, this is causing the font size of 8 appering the new replaced document.

May you please suggest the cause of this behavious.

Is this is a bug in Aspose library or can it be avoided using the certain feature of Aspose

Product - Aspose.Words for .NET
Version - 2016.05.31

Method to replace the text -

Method to replace the text -

public ReplaceText(Aspose.Words.Document report, string oldValue, string newValue, string newDocPath)
{
	foreach (Section section in report.Sections)
	{
		foreach (Paragraph paragraph in section.Body.GetChildNodes(NodeType.Paragraph, true))
		{
			foreach (Run run in paragraph.Runs)
			{
				run.Text = run.Text.Replace(oldValue, newValue);
			}
		}
	}
	report.Save(newDocPath, SaveFormat.Docx);
}

Document.xml Before Text Replacement -

<w:r>
<w:rPr>
<w:lang w:val=“en-US” />
</w:rPr>
<w:t>${Board.GetCcy1()}$</w:t>
</w:r>
Document.xml Before Text Replacement -

<w:r>
<w:rPr>
<w:sz w:val=“16” />
<w:lang w:val=“en-US” />
</w:rPr>
<w:t>USD</w:t>
</w:r>


This Topic is created by tahir.manzoor using the Email to Topic plugin.

@nagendran.venkat,

Thanks for your inquiry. There is no need to iterate over all paragraph and run nodes of document. Please use Range.Replace method to replace all occurrences of a specified string with another string. Please refer to the following article.
Find and Replace

If you still face problem, please share your input and expected output documents. We will then provide you more information about your query along with code.

Thanks for coming back to me I only gave you a simplified version of the code to understand the problem.

The actual logic is much more complex and I can’t do replacement on range.

May you please suggest the reason on inserting the font size of 8.

@nagendran.venkat.uni,

Thanks for your inquiry. Unfortunately, it is difficult to say what is the problem without documents. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Old and new text values that you are passing to ReplaceText method.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.