Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Introducedin
8.34
8.34
Description

Excerpt

Sets the ShowValueAs properties of a PivotTable.

...

Signature
vb.net
vb.net
public Function SetShowValueAs(ByVal showValueAs As PivotTableFieldShowValueAs.ShowValueAsType, ByVal baseField As SourceField, ByVal baseItemIndex As Integer)

...

Example
Code Block
csharp
csharp
titleC#
ExcelApplication xla = new ExcelApplication();
          Workbook wb = xla.Open(@"C:\MySpreadsheet.xlsx");
          Worksheet ws = wb.Worksheets[0];
          PivotTable pt = ws.PivotTables[0];
          DataField df = pt.DataFields[0];
          df.SetShowValueAs(PivotTableFieldShowValueAs.ShowValueAsType.Difference, pt.SourceFields[0], 0);
Code Block
vb.net
vb.net
titlevb.net
Dim xla As New ExcelApplication()
          Dim wb As Workbook = xla.Open("C:\MySpreadsheet.xlsx")
          Dim ws As Worksheet = wb.Worksheets(0)
          Dim pt As PivotTable = ws.PivotTables(0);
          Dim df As DataField = pt.DataFields(0)
          df.SetShowValueAs(PivotTableFieldShowValueAs.ShowValueAsType.Difference, pt.SourceFields(0), 0);
Remarks

This property cannot be set on CalculatedFieldsValuesLabels. You can check if a PivotField is calculated field with the IsCacluatedField IsValuesLabel Property

This is the same as going to Value Field Settings > Show values as.

When calling SetShowValueAs(), certain ShowValueAsTypes use a source field as a base field and an index for one of the values in the data source column associated with the source field. The base field and value specified by the base item index are used to compute the values shown in the PivotTable.

Use PivotTableFieldShowValueAs.BaseItemNext and PivotTableFieldShowValueAs.BaseItemPrevious to specify Next or Previous.