I'm using GemBox.Document to create a Word document that's generated from combining multiple documents and I'm inserting the TOC element (Table of Content) at the beginning. Now I need to alphabetize that TOC element.
I'm aware that this option doesn't exist in Microsoft Word, the TOC is always sorted in page order, not in alphabetical order, and that the TableOfEntries.Update() method behaves like that by default.
Nevertheless, I'm hoping there is a way to do that. I did check those TOC switches and if I'm not missing something, there is no switch for this, right?
Last, I'm aware of index tables, but that's not what I'm looking for. The TOC element is a much better fit to what I'm trying to get, but I need it sorted alphabetically.
You can "manually" sort the TOC entries after updating the TOC element, like this:
But note that when the TOC element is updated again, either with GemBox.Document or with some Word application, you will get unsorted entries.
The only thing you can do here is to prevent others from updating your TOC element, for example by removing the TOC and keeping just its entries (aka unlinking the Table of Content):
Or you could place the TOC in a protected Section and thus prevent TOC update from Word applications (note that you'll still be able to update it with GemBox.Document):