A frequently appearing request for Word export templates is how to generate a Table of Figures or a Table of Tables automatically.
This wiki page describes a possible solution for this requirement using a special Word template.
The solution is:
- When you have a picture that you want to appear in the Table of Figures then edit the wiki text of the item, and add special wiki comment or a special footnote link in the text just before the picture like this:
- Enter as hidden wiki comment:
//WordFigure: an example figure
[!picture.png!]
- Or as a footnote link:
[an example figure|#WordFigure]
[!picture.png!]
- When you have a table that you want to appear in the Table of Tables then similarly add a special wiki comment like this:
//WordTable: example table
||an example table|x
- Or as a footnote link:
[an example table|#WordTable]
||an example table|x
During the Word export the TableOfFiguresTemplate3.docx will transform these special wiki comments or footnotes to Word's native Table of Figures control. The Table of Figures is a table of content that will contain links those point and jump to the pictures marked with the //WordFigure:name comment. Similarly the //WordTable:name places are appearing in the Table of Tables control in Word.
The final result will look like this, you can have a look at an example result document too: result.docx
The special footnote-link can be added using the Wysiwyg editor like this:
- Click on insert link icon inside Wysiwyg editor
- In the dialog enter #WordFigure or #WordTable as URL, plus the text of the Table or Picture:
- Save and the footnote link will appear as:
How does it work?
The example Word template transforms the special wiki markups like //WordFigure and //WordTable or the footnote markups to Word's native Table of figures.This is implemented as:
- During the Word export the HTML output of the exported items/wiki text is captured into String variables.
- The HTML output is parsed using JSoup java library and the HTML is modified to contain the necessary Word specific HTML markup which will appear as Words' native SEQ fields during Word export.
- When Word opens the result document then the Word's Table Of Figures control will find and contain these special SEQ fields: