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

Free Support Forum - aspose.com

Replace arrows in a document template

I have a small but kind of a big issue on my plate. I thought of sharing with you guys and see whether you have any solutions for that.
Description :
I use Aspose word to generate this report.
In the template we have multiple strings like ##LegPressMan##, ##MyMan## and also an arrow which points the string in to respective effective area of the body. I’ll replace the strings one by one and I need to delete the unfilled ones and clean the document at the end.

After replacing the values doc will look like this

Problem is I have no way to remove the pointing arrow with the string I’m deleting. I tried grouping the string and arrow but it didn’t work.

Hi Grant,

Thanks for your inquiry.

As long as the anchor of the shape is in the same paragraph, you can use the code like below (make sure to run it before the runs of text are removed).

args.MatchNode.ParentNode.GetChildNodes(NodeType.Shape, true).Clear();

If this does not work, could you please attach your template here for testing?

Thanks,

Hi Adam

Thank you very much for the reply. But I still couldn’t get this running.
My problem is
There is a picture and some text fields and I need to replace them with values.

  1. I have attached a sample document
  2. They all will have this pattern ##CoreEnduranceMan## --> ##SomthingMan##
  3. I am using ^##([a-zA-Z]*)##$ regex to match the values and even tried ^##([a-zA-Z]*)Man##$
  4. var theManValue = new Regex("^##([a-zA-Z]*)##$");
    theReport.Range.Replace(theManValue, string.Empty);
  5. And also I tried
    Range.Replace(theManValue , new InsertDocumentAtReplaceHandler(), false); without any luck
    6.Also If possible I need to delete the related pointing arrows

Any help in this regard is highly appreciated!
Thanks

Hello
Thanks for your request. In your case you should use Mail Merge feature. Please follow this link to learn more:
https://docs.aspose.com/words/net/mail-merge-and-reporting/
Please see the following simple code:

Document doc = new Document("C:\\Temp\\Summary.docx");
// Execute mail merge
doc.MailMerge.Execute(new string[] { "##ChinUpsMan##", "##CoreEnduranceMan##", "##VerticalJumpMan#", "##PushUpsMan##" },
new object[] {"Test1", "Test2", "Test3", "Test4"});
doc.Save("C:\\Temp\\out.docx");

Best regards,

Hi Andrey
Thanks for the reply. By using mailmerge can I delete the unfilled tags also the related pointing arrows?
Thanks
Amila

Hello
Thanks for your inquiry. You can use MailMerge.RemoveEmptyParagrapgs property in this case. Please follow the link to learn more:
https://docs.aspose.com/words/net/clean-up-before-or-during-mail-merge/
Hope this helps.
Best regards,