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

Figure 20-34. Illustrating the Calculation property

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 )

20.7.9 CurrentPage Property

This property returns or sets the current page. It is only valid for page fields. Note that the

property should be set either to the name of the page field or to "All" to show all pages.

20.7.10 DataType Property

This read-only property returns a constant that describes the type of data in the pivot field. It can

be one of the following XlPivotFieldDataType constants:

Enum XlPivotFieldDataType

xlText = -4158

xlNumber = -4145

xlDate = 2

End Enum

20.7.11 HiddenItems and VisibleItems Properties

The HiddenItems property returns the PivotItems collection of all hidden PivotItem objects, using

the syntax:


It can also return a single or an array of hidden PivotItem objects using the syntax:


where Index is a single index or an array of indexes.

Similarly, the VisibleItems property returns a PivotItems collection of all visible PivotItem objects

or a single or an array of such objects. The syntax is the same as for the HiddenItems property.

20.7.12 MemoryUsed Property


This read-only property returns the amount of memory currently being used by the PivotField (it

also applies to PivotItem objects) as a Long integer.

20.7.13 ServerBased Property

This read-write Boolean property applies to page fields only and is used with (generally very large)

external data sources. It is True when the PivotTable's data source is external and only the items

matching the page-field selection are retrieved.

By setting this property to True, the pivot cache (discussed later in the chapter) needs to

accommodate only the data for a single page field. This may be important, or even necessary,

when the external data source is large. The trade-off is that each time the page field is changed,

there may be a delay while Excel requeries the original source data to retrieve data on the new

page field.

Note that there are some circumstances under which this property cannot be set to True:

The field is grouped.

The data source is not external.

The cache is used by more than one PivotTable.

The field has a data type that cannot be server-based (such as a memo field or an OLE


20.7.14 ShowAllItems Property

This read-write Boolean property is True if all items in the PivotTable are displayed. The default

value is False, in which case the pivot items that do not contribute to the data fields are not

displayed. Note that this property corresponds to the "Show items with no data" check box on

Excel's PivotTable Field dialog box.

To illustrate, suppose we add a single row to our source table:








This row creates a new store type but adds data only for Boston. The resulting pivot table will

have the default appearance shown in Figure 20-35. Since ShowAllItems is False, there are no

rows for the new store type corresponding to Los Angeles or New York.

Figure 20-35. ShowAllItems = False


On the other hand, the code:

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

PivotFields("Store Type").ShowAllItems = True

will produce the pivot table shown in Figure 20-36.

Figure 20-36. ShowAllItems = True


20.7.15 Subtotals Method

This method returns or sets the display of a particular type of subtotal for the specified pivot field.

It is valid for all fields other than data fields. The syntax is:


where the optional Index parameter indicates the type of subtotal and is a number from Table 20-4.













Table 20-4. Values for the Subtotals Method's Index Parameter


Subtotal Type








Count Nums





For instance, the following code requests a display of subtotals for both Sum and Count:


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

PivotFields("Store City").Subtotals(2) = True

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

PivotFields("Store City").Subtotals(3) = True

We can also set the Subtotals property to an array of 12 Boolean values to set multiple subtotals.

For instance, the following code displays all subtotals:

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

PivotFields("Store City"). _

Subtotals = Array(False, True, True, True, True, _

True, True, True, True, True, True, True)

Note that we set Automatic to False in this array, since if Automatic is set to True, then all

other values are set to False (thus providing a quick way to set all subtotals to False).

If this argument is omitted, the Subtotals method returns an array containing a Boolean value for

each subtotal.

20.8 The PivotCache Object

Pivot tables can manipulate the source data in a variety of ways, and this can require a great deal

of processing power. For maximum efficiency, the data for a pivot table is first stored in memory

in what is referred to as a pivot cache. The pivot table, itself, actually provides various views of

the pivot cache. This allows manipulation of the data without the need to access the original

source further which might, after all, be an external data source.

The PivotCache object represents a pivot table's cache. It is returned by the PivotCache method of

the PivotTable object. Let us take a look at some of the main properties and methods of the

PivotCache object.

20.8.1 Refreshing a Pivot Cache

The Refresh method refreshes both the pivot cache and the pivot table.

However, we can prevent a pivot table from being refreshed, either through the user interface (the

Refresh data menu item on the PivotTable menu) or through code, by setting the EnableRefresh

property to False.

The read-write Boolean RefreshOnFileOpen property is True if the PivotTable cache is

automatically updated each time the workbook is opened by the user. The default value is False.

Note that this property is ignored if the EnableRefresh property is set to False. Note also that the

PivotTable cache is not automatically refreshed when the workbook is opened through code, even

if RefreshOnFileOpen is True.

The RefreshDate property returns the date on which the pivot cache was last refreshed, and the

RefreshName property returns the name of the user who last refreshed the cache.

20.8.2 MemoryUsed Property

The read-only MemoryUsed property applies to either a PivotCache object or a PivotField object

and returns the amount of memory currently being used by the cache, in bytes.


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