Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating RTF headings compatible with Microsoft Word

Tags:

ms-word

rtf

I am producing a script which creates RTF documents and want to add a table of contents. I've opted for this:

{\field\flddirty\fldedit{\*\fldinst TOC}{\fldrslt \i Use this page to add the table of contents, right click to update field \i0}}

and the user will open the RTF in Microsoft Word and update the field. However, I'm unsure of how to format the sections in my RTF code to create headings so that when I update my TOC in Word it will show the sections. For now, when I "update field", I only get "No tables of contents entries found"

I've tried {\tc My heading here} with no luck.

Is there some code I can insert into my RTF to format my text as headers for TOC formatting in Word?

like image 407
gimmian Avatar asked Nov 06 '25 17:11

gimmian


1 Answers

I've figured out how to solve my problem. In Microsoft word, in order for {\tc Heading here } to appear in your table of contents, you must include Table entry fields. To incorporate this into your RTF code, instead of {\*\fldinst TOC} use {\*\fldinst TOC \o \h \f} \h enables HTML links and \f enables table entry fields. Now when you update the field, your {\tc Heading here } will appear in the table of contents.

This article helped me out: https://support.office.com/en-ca/article/Table-of-Contents-III-Use-fields-to-create-a-TOC-and-create-multiple-TOCs-f1509cfe-b48f-4ac5-8241-89a6619d7d6f

like image 54
gimmian Avatar answered Nov 10 '25 00:11

gimmian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!