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

Free Support Forum - aspose.com

Using Sections Names instead of Index


I’m creating Word templates and using the Merge Fields functionality to dynamically create Word documents. I would like to dynamically add and remove sections (or paragraphs). This will be determined by a form field value, which will be associated to each section. Currently Aspose allows accessing sections with index rather than names. My concern is if a section in template is removed or moved to a different place in the same template, say section 1, now that section will have a different index, say section 5 (if the section is moved to a different place in the same template itself).

Also, all the other section’s index in the template will be affected by this change. Now, I’ve to update the code and underlying program logic to keep up with the change.

Is there any other alternative to this issue. All I want is to remove a block of text (with merge fields and static text), based on form field value from a template, irrespective of whether the block of text in template is moved somewhere or removed from the template.

Any help is much appreciated.



This message was posted using Email2Forum by alexey.noskov.

Thank you for your interest in Aspose.Words. There is no way to specify name of Word document section. However, I think you can use bookmarks to achieve this. Just insert bookmark at the beginning of the section with name “sect1” for example. In this case, you will be able to use code like the following:

Section sect = (Section)doc.Range.Bookmarks["sect1"].BookmarkEnd.GetAncestor(NodeType.Section);
Or the following code:
Section sect = builder.CurrentSection;

Hope this could help you.
Best regards.

Thank you for the quick response. For now, this seems like a good work around. I’ll definitely contact you if further assistance is needed.
Thank you.