Main Content

Update Tables of Contents and Generated Lists in Word Documents

When you generate a Microsoft® Word report that includes a table of contents or a list of figures, tables, or other report elements, the report generation software generates a placeholder for the table of contents or list. To generate the items in the table of contents or list, you must update the Word document programmatically or interactively. If you open the Word document without updating it, the table of contents and generated lists appear to be empty.

Update Word Documents Programmatically

To update a Word document programmatically, you can use rptview or docview.

To update and display the document, use rptview. If you later open the document in Word, the table of contents and other generated lists are visible. You can use rptview on a Windows® or Macintosh platform. Here is an example of a report generation program that uses rptview:

import mlreportgen.report.*
rpt = Report('myreport','docx');
add(rpt, TitlePage('Title','My Report'));
add(rpt,TableOfContents);
add(rpt,Chapter('Title','Introduction','Content','Hello World'));
close(rpt);
rptview(rpt);

On a Windows platform, to update the document without displaying it, use docview. Here is an example of a report generation program that uses docview:

import mlreportgen.report.*
rpt = Report('myreport','docx');
add(rpt,TitlePage('Title','My Report'));
add(rpt,TableOfContents);
add(rpt,Chapter('Title','Introduction','Content','Hello World'));
close(rpt);
docview(rpt.OutputPath,'updatefields','closedoc');

Update Word Documents Interactively

To update a Word document interactively, select all of the document contents and then update the selected contents. You can use these keyboard and function key shortcuts:

  • On a Windows platform, press Ctrl+A and then press F9.

  • On a Macintosh platform, press Command+A and then press F9.

See Also

| | | | | | | | | |

Related Topics