Word: Styleref fields


Microsoft Word offers a very interesting field called STYLEREF. Quoting from Office Help:

The StyleRef field inserts text that’s formatted with the specified style. When inserted in a header or footer, the StyleRef field prints the first or last text formatted with the specified style in the document body of the current page, allowing you to print dictionary-style headers or footers.

An RPE example showing STYLEREF usage is available for download on the RPE DevWorks Template Library  here. You should observe the two fields in the master page, the Word “update fields” value in the docspec and the Word output included.

If you look at the flag supported for this field you will see it can include either the content or the numbering of the last paragraph with the specified style. In other words you can easily reference/reuse the content of a paragraph.

This of course has many applications and in general can simplify template design:

  • putting content in header and footer
  • generating bilingual documents while keeping consistent heading numbering
  • injecting text in the middle of a paragraph
  • etc

To use it in RPE you need to use the FIELD element from the palette and enter :

  • STYLEREF “<style name>” – for the content of the style
  • STYLEREF “<style name>”  \n – for the numbering of the style

styleref_1

REMEMBER that in order for fields to be caculated in the RPE output you need to run a macro or, with 1.2.1 and newer, set the update fields property of the Word output to true.

More information and usage sample on STYLEREF:

Advertisements

Author: Dragos Cojocari

Architect for Rational Publishing Engine

1 thought on “Word: Styleref fields”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s