1. Trang chủ >
  2. Công Nghệ Thông Tin >
  3. Quản trị mạng >

Table 20-3. Members of the PivotField Object

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.72 MB, 490 trang )


AddPageItem

Application

AutoShow

AutoShowCount

AutoShowField

AutoShowRange

AutoShowType

AutoSort

AutoSortField

AutoSortOrder

BaseField

BaseItem

CalculatedItems

Calculation

Caption

ChildField

ChildItems

Creator

CubeField

CurrentPage

CurrentPageList



DatabaseSort

DataRange

DataType

Delete

DragToColumn

DragToData

DragToHide

DragToPage

DragToRow

DrilledDown

EnableItemSelection

Formula

Function

GroupLevel

HiddenItems

HiddenItemsList

IsCalculated

IsMemberProperty

LabelRange

LayoutBlankLine

LayoutForm



LayoutSubtotalLocation

MemoryUsed

Name

NumberFormat

Orientation

Parent

ParentField

ParentItems

PivotItems

Position

PropertyOrder

PropertyParentField

ServerBased

ShowAllItems

SourceName

StandardFormula

SubtotalName

Subtotals

TotalLevels

Value

VisibleItems



Let us take a look at some of these members.



20.7.1 AutoShow-Related Members

The AutoShow method is used to restrict the display of pivot items for a given pivot field. The

syntax is:

PivotFieldObject.AutoShow(Type, Range, Count, Field)



All parameters are required for this method.

The Type parameter has two possible values: xlAutomatic activates the remaining parameters

and, thereby, causes the restrictions to take effect, and xlManual disables the remaining

parameters and causes Excel to remove any restrictions caused by a previous call to this method

with Type equal to xlAutomatic.

The other parameters can be described by the following sentence: restrict pivot items to the top

(Range =xlTop) or bottom (Range =xlBottom) Count pivot items based on the value in

pivot field Field.

Thus, for instance, referring to Figure 20-10, the code:

ActiveSheet.PivotTables("Sales&Trans"). _

PivotFields("Store Type").AutoShow _

xlAutomatic, xlTop, 1, "Sale"



shows the top (Range =xlTop and Count=1) Store Type based on the value of Sale. The result

is shown in Figure 20-24.



318



Figure 20-24. Illustrating AutoShow



As you can see, the top sales in Boston are from the company stores, whereas the top sales in the

other cities are in franchise stores.

The same code as the previous but with Type set to xlManual will remove the restrictions and

restore the original pivot table:

ActiveSheet.PivotTables("Sales&Trans"). _

PivotFields("Store Type").AutoShow _

xlManual, xlTop, 1, "Sale"



The following properties are associated with AutoShow:

AutoShowCount property

The read-only AutoShowCount property returns the number of items that are

automatically shown in the pivot field (this is the Count parameter of the AutoShow

method).

AutoShowField property

This read-only property returns the name of the data field used to determine which items

are shown (this is the Field parameter of the AutoShow method).

AutoShowRange property

This read-only property returns xlTop or xlBottom. This is the value of the Range

parameter of the AutoShow method.

AutoShowType property

This read-only property returns xlAutomatic if AutoShow is enabled for the pivot field

and xlManual if AutoShow is disabled.



20.7.2 Sorting Pivot Fields

The AutoSort method sets the automatic field-sorting rules for the pivot field. The syntax is:



PivotFieldObject.AutoSort(Order, Field)



319



The Order parameter specifies the sort order and is one of the following constants:

Enum XlSortOrder

xlAscending = 1

xlDescending = 2

End Enum



It can also be set to xlManual to disable automatic sorting. The Field parameter is the name of

the field to use as the sort key.

For instance, referring to Figure 20-10, the code:

ActiveSheet.PivotTables("Sales&Trans"). _

PivotFields("Store Type").AutoSort _

xlAscending, "Sale"



sorts by Sale and produces the results shown in Figure 20-25. Note the order of the Store Type

items for Boston as compared to the other cities.

Figure 20-25. Illustrating AutoSort



The read-only AutoSortField property returns the name of the key field and the AutoSortOrder

property returns the sort order of the pivot field (xlAscending, xlDescending, or

xlManual).



20.7.3 The Fundamental Properties

The PivotField object has a handful of basic properties that you will almost always want to set.

20.7.3.1 Function property

This property applies only to data fields and returns or sets the aggregate function used to

summarize the pivot field. It can be one of the following XlConsolidationFunction

constants:

Enum XlConsolidationFunction



320



xlVarP = -4165

xlVar = -4164

xlSum = -4157

xlStDevP = -4156

xlStDev = -4155

xlProduct = -4149

xlMin = -4139

xlMax = -4136

xlCountNums = -4113

xlCount = -4112

xlAverage = -4106

xlUnknown = 1000

End Enum



' Excel 9 only



20.7.3.2 NumberFormat property

This property applies only to data fields and returns or sets the formatting string for the object.

Note that it will return Null if all cells in the specified range do not have the same number format.

This is a read-write string property.

20.7.3.3 Orientation property

This property returns or sets the orientation of the pivot field. It can be set to one of the following

values:

Enum XlPivotFieldOrientation

xlHidden = 0

xlRowField = 1

xlColumnField = 2

xlPageField = 3

xlDataField = 4

End Enum



20.7.3.4 Position property

This read-write property returns or sets the position of the pivot field among all pivot fields in the

same area (row, column, page, or data).



20.7.4 Selecting Ranges

The PivotField object has two properties related to selecting portions of the pivot table related to

the field.

20.7.4.1 DataRange property

This property returns a Range object representing the value area associated with the given

PivotField. To illustrate, the code:

ActiveSheet.PivotTables("Sales&Trans"). _

PivotFields("Store Type"). _

DataRange.Select



results in Figure 20-26.

Figure 20-26. DataRange for Store Type



321



20.7.4.2 LabelRange property

The LabelRange property returns a Range object that represents the label cells for the PivotField.

To illustrate, the code:

ActiveSheet.PivotTables("Sales&Trans"). _

PivotFields("Store Type"). _

LabelRange.Select



will select just the cell containing the button labeled Store Type in Figure 20-26.



20.7.5 Dragging Pivot Fields

The PivotField object has some properties that can prevent the user from moving the field. They

are as follows (all default values are True):

DragToColumn property

Set to False to prevent the field from being dragged to the column area.

DragToHide property

Set to False to prevent the field from being hidden by being dragged off of the pivot

table.

DragToPage property

Set to False to prevent the field from being dragged to the page field area.

DragToRow property

Set to False to prevent the field from being dragged to the row field area.



20.7.6 Name, Value, and SourceName Properties



322



Xem Thêm
Tải bản đầy đủ (.pdf) (490 trang)

×