5.3 Creating multi-column documents

Creating multi-column documents

Maybe tables are overkill for what you need. Perhaps you just need to lay out your text in multiple columns. Interactively, you do that through the Format menu by choosing Columns. That brings up the Columns dialog shown in Figure 7. You can specify the number of columns, the width of each, and the spacing between them.

Figure 7. Specifying columns. This Word dialog lets you indicate how many columns you want, their width, and how far apart they are.

In Automation, columns are specified by a TextColumns collection, which is a member of a PageSetup object. (See the section "Setting up pages" in Chapter 4 for more on the PageSetup object.) In addition to the usual collection properties, TextColumns has several properties specific to its role, shown in Table 5.

Table 5. Setting up columns. The TextColumns collection contains TextColumn objects, but it has several properties that apply to the collection as a whole.

Property

Type

Description

EvenlySpaced

Logical or Numeric

Indicates whether the columns are evenly spaced.

Width

Numeric

Width of the columns in points, if they re evenly spaced.

Spacing

Numeric

Distance between columns in points, if they re evenly spaced.

LineBetween

Logical

Indicates whether a vertical line appears between columns. Not visible in the Normal view; use the Print Layout or Print Preview views to display them. Additionally, the lines are only displayed when text is contained in the columns.

As with other collections, the Add method adds new columns. But TextColumns has a special method, SetCount, which can be used to set the number of columns. Think of SetCount as a shortcut a way to avoid having to call Add repeatedly.

The TextColumn object is a little simpler than the TextColumns collection. It has only two properties worth noting: Width and SpaceAfter. Width serves the same role here as it does for the collection, except that it affects only a single column. SpaceAfter corresponds to the collection s Spacing property. Beware: setting either Width or SpaceAfter for any column changes Width and Spacing for the collection to wdUndefined (9999999) and sets the collection s EvenlySpaced property to .F., even if the value you assign is the same as the collection-level value. To restore the collection-level values, set EvenlySpaced to .T. for the collection.

Here s the code to set up a new document with three columns the first two equally spaced, the third wider with a vertical line between them:

oDocument = oWord.Documents.Add()

WITH oDocument.PageSetup

.TextColumns.SetCount(3)

.TextColumns[1].Width = oWord.InchesToPoints(1.5)

.TextColumns[1].SpaceAfter = oWord.InchesToPoints(.25)

.TextColumns[2].Width = oWord.InchesToPoints(1.5)

.TextColumns[2].SpaceAfter = oWord.InchesToPoints(.25)

.TextColumns[3].Width = oWord.InchesToPoints(2.5)

.TextColumns.LineBetween = .T. && Put in some text to see the lines.

ENDWITH

When sending code to fill the columns, you move from one column to the next with the InsertBreak method. This method takes a single parameter indicating the type of break. There s a set of constants for the breaks for a column break, it s wdColumnBreak, with a value of 8. So, to move to the next column, use this:

#DEFINE wdColumnBreak 8

oRange.InsertBreak( wdColumnBreak )

Be sure to collapse the range (see the section "Moving in a range or selection" in Chapter 4) before inserting the column break; otherwise, the column break replaces the range.

 

Copyright 2000 by Tamar E. Granor and Della Martin All Rights Reserved



Microsoft Office Automation with Visual FoxPro
Microsoft Office Automation with Visual FoxPro
ISBN: 0965509303
EAN: 2147483647
Year: 2000
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net