Formatting Field Results

Unless you add a switch inside the field to change formatting, the field result takes on the formatting of the first nonblank character of the field.

For example, if you have a field that says {Author} , with the "A" in Times New Roman, 10-point italic, the result of the field takes on that formatting: Douglas Adams.

Word has three different field switches that control the appearance and formatting of field code results.

General * Format Switches

The most common field switch is the general formatting switch:

* mergeformat

This switch tells Word to ignore the formatting of the first character of the field, and instead to use whatever formatting you apply to the field itself.

For example, say you're typing along in 12-point Garamond, and you insert a {NumWords} field (which shows the number of words in the document), using the Field dialog box. If you check the Preserve Formatting During Updates box, Word inserts a * mergeformat switch:

{NUMWORDS  * MERGEFORMAT}

With that switch in place, every time you update the field, it takes on the original formatting—Garamond 12 point—unless you apply some different formatting directly on the field result.

Formatting switches gives you an enormous amount of flexibility in how a field appears in your document—for example

* dollartext

converts a number—say, 123.45—into the kind of text you put on a check—one hundred twenty-three and 45/100.

* caps

capitalizes the initial letters of each word in the field result. Combine the two formatting switches with the = field, which evaluates numeric expressions, to get the field:

{= 123.45 * dollartext * caps}

which appears in your document as

One Hundred Twenty-Three And 45/100

The most useful formatting switches are detailed in Table 19.1.

Table 19.1. * Formatting Switches
Switch Action
* mergeformat Retains the current formatting of the field result whenever it's updated.
* charformat Uses the formatting applied to the first nonblank character of the field code.
* caps Capitalizes the first letter of each word.
* firstcap Capitalizes the first letter of the first word only.
* lower Makes all letters lowercase.
* upper Makes all letters uppercase.
* cardtext Converts a number to text: 12 becomes twelve.
* ordtext Converts a number to the ordinal text: 12 becomes twelfth.
* Roman Displays a number in capitalized Roman numerals: 12 becomes XII.
* dollartext Spells out the whole part of the number, then rounds the fraction and appends "and xx/100": 123.456 becomes one hundred twenty-three and 46/100.

Numeric # Picture Switches

Word also allows you to specify a numeric "picture" switch to be applied to numbers. This could come in handy if, for example, you calculate numbers in a table or bring them in for a merge, and you want to show negative numbers in parentheses.

The basic building blocks of field numeric pictures are as follows:

  • Decimal point

  • Thousands separator (typically a comma)

  • Zero (digits that always appear)

  • # sign (digits that are used only if necessary)

  • Various combinations to format negative numbers; and literal text, which appears in the field result.

You could practically write an entire book on the nuances of numeric picture formatting. Rather than dwell on the details, examine the common numeric picture elements shown in Table 19.2.

Table 19.2. Common # Numeric Picture Elements
Switch Result
* 00.00 Forces Word to display two digits to the left and two to the right of the decimal point, adding leading and trailing zeros as needed: 1.2 displays as 01.20 and –1.2 shows up as –01.20. Use this format when you want numbers in a column to line up perfectly.
* #0.000 One or more digits might appear to the left of the decimal point, but three must appear after: 1.23 displays as 1.230, –12.3456 becomes –12.346, and 1234.5 shows 1234.500.
* $,#.00 Shows a dollar sign, followed by the number with commas grouping each set of three digits, and two decimal places: .12 appears as $.12, 12345.678 shows $12,345.68.
* $,0.00 Same as the preceding, but always shows at least one digit for dollars: .12 displays as $0.12.

Unless you specify a different format, Word always displays negative numbers with a leading minus sign. To force Word to show negative numbers in parentheses, you have to provide two formatting pictures, the first for positive numbers and the second for negatives, enclosed in quotes, separated by a semicolon. For example, this format

# "$,#.00;($,#.00)"

will show 0.123 as $.12 and –1234.56 as ($1,234.56).

Date-Time @ Format Switches

The date-time picture switch almost always appears in a {Date}, {Time} , {Createdate}, {Printdate} , or {Savedate} field. (The last three fields show when the document was created, last printed, or last saved.) The switch tells Word how to format the date or time. For example, add this field to a document:

{Date @ "MMMM d, yyyy - h:mm:ss AM/PM"}

When you open the document on the morning of Bill Gates'fiftieth birthday, Word updates the field and displays text that looks like this:

October 28, 2005 - 8:33:05 AM

The most common date-time picture elements are shown in Table 19.3.

Table 19.3. @ Date-time Picture Elements
Element Meaning
M Month number without leading 0: August is 8
MM Month number with leading 0: August is 08
MMM Month as three-letter abbreviation: Aug
MMMM Month spelled out: August
d Day of the month without leading zero
dd Day of the month with leading zero
ddd Day of the week as three-letter abbreviation: Mon
dddd Day of the week spelled out: Monday
yy Last two digits of the year: 01
yyyy Four-digit year: 2001
h Hour on a 12-hour clock without leading zero
hh Hour on a 12-hour clock with leading zero
H Hour on a 24-hour clock without leading zero
HH Hour on a 24-hour clock with leading zero
m Minutes without leading zero
mm Minutes with leading zero
s Seconds without leading zero
ss Seconds with leading zero
AM/PM AM or PM (used with h and hh for 12-hour clock)
Text Appears as text in the field result

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.69.152