We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Character Font type issue with FindReplaceOptions

We are unable to assign a Font style (“formlink”) or any styles to FindReplaceOptions object. Please find the below code snippet which throws Null reference exception. Looks like the options.ApplyFont only has Get property not Set property.

FindReplaceOptions options = new FindReplaceOptions();
options.ApplyFont.Bold = true;
// options.ApplyFont.Style.Font.Style = style;
options.ApplyFont.Style = style;

@Sridhar34689 Could you please ZIP and upload your input document where the font style being searched is located? Could you please also provide the code that demonstrates how this style is obtained?

StyleTemplate.7z (25.1 KB)
Attached requested details.

@Sridhar34689 Thank you for additional information. We are working on your request and will reply you soon.

@Sridhar34689 Unfortunately, there is no possibility to set the style for replacement directly in FindReplaceOptions at the moment. I have logged this problem in our issue tracking system as WORDSNET-23392. You will be notified via this forum thread once this issue has been resolved.
I noticed in the code you sent that you are using ReplacingCallback. While the ticket is being processed, I suggest you the following code as a workaround.

private class ReplacingCallback : IReplacingCallback
    public ReplaceAction Replacing(ReplacingArgs args)
        Run run = args.MatchNode as Run;
        run.Font.StyleName = "formlink";

        return ReplaceAction.Replace;

We apologize for your inconvenience.

Thanks for providing details. I want to apply this changes in specific value inside paragraph not whole Node. ( Please refer my attached document details)
args.Match.Value instead of args.MatchNode.
I can appreciate if I get an answer exactly what I am looking.


Unfortunately, the code you sent does not contain implementation of ReplacingCallback on your part. Therefore, it is difficult to consider the details.
If style assignment within ReplacingCallback is not what you expect, then could you please explain what you expect from the assignment?

options.ApplyFont.Style = style;

Please note that the style assignment issue logged in our issue tracking system WORDSNET-23392 has been resolved. You will be able to get this fix in the next release.

The issues you have found earlier (filed as WORDSNET-23392) have been fixed in this Aspose.Words for .NET 22.2 update also available on NuGet.

I have updated to .NET 22.2 but still style issue have not been fixed.

@Sridhar34689 You can now use FindReplaceOptions.ApplyFont.Style. Assigning the specified property no longer results in Null reference exception. If Document.Range.Replace is executed, all matching nodes receive this style.

Document doc = new Document("InputTemplate.docx");
Style style = doc.Styles.FetchByName("formlink");
FindReplaceOptions options = new FindReplaceOptions();
options.ApplyFont.Style = style;
doc.Range.Replace("Application", "App", options);