XLSX

Pivot Tables

Create pivot tables from source data with 11 aggregation functions

Basic Pivot Table

Create a pivot table from a source data range, grouping by row fields and aggregating data:

{
  "worksheets": [
    {
      "name": "Data",
      "rows": [
        { "cells": [{ "value": "Region" }, { "value": "Product" }, { "value": "Sales" }] },
        { "cells": [{ "value": "East" }, { "value": "Widget" }, { "value": 150 }] },
        { "cells": [{ "value": "East" }, { "value": "Gadget" }, { "value": 200 }] },
        { "cells": [{ "value": "West" }, { "value": "Widget" }, { "value": 300 }] },
        { "cells": [{ "value": "West" }, { "value": "Gadget" }, { "value": 100 }] },
        { "cells": [{ "value": "North" }, { "value": "Widget" }, { "value": 250 }] },
        { "cells": [{ "value": "North" }, { "value": "Gadget" }, { "value": 175 }] }
      ]
    },
    {
      "name": "Pivot",
      "rows": [],
      "pivotTables": [
        {
          "source": "A1:C7",
          "sourceSheet": "Data",
          "location": "A3",
          "rows": ["Region"],
          "data": [{ "field": "Sales", "summarize": "sum" }]
        }
      ]
    }
  ]
}

Aggregation Functions

All 11 ST_DataConsolidateFunction types from OOXML are supported:

Functionsummarize valueDescription
Sum"sum"Sum of values (default)
Average"average"Arithmetic mean
Count"count"Count of non-empty
Count Numbers"countNums"Count of numbers
Max"max"Maximum value
Min"min"Minimum value
Product"product"Product of values
StdDev (sample)"stdDev"STDEV.S
StdDevP (population)"stdDevp"STDEV.P
Var (sample)"var"VAR.S
VarP (population)"varp"VAR.P

Multiple Data Fields

Add multiple aggregations in the same pivot table:

{
  "pivotTables": [
    {
      "source": "A1:C7",
      "sourceSheet": "Data",
      "location": "A3",
      "rows": ["Region"],
      "data": [
        { "field": "Sales", "summarize": "sum", "name": "Total Sales" },
        { "field": "Sales", "summarize": "average", "name": "Avg Sales" }
      ]
    }
  ]
}

Filters

Apply pivot filters to restrict which data appears in the pivot table. Use the PivotFilterTypeValue enum for filter types:

import { PivotFilterTypeValue } from "@office-open/xlsx";

pivotTables: [
  {
    source: "A1:C9",
    sourceSheet: "Data",
    location: "A3",
    rows: ["City"],
    data: [{ field: "Revenue", summarize: "sum" }],
    filters: [
      {
        fld: 0,
        type: PivotFilterTypeValue.CAPTION_NOT_EQUAL,
        id: 1,
        stringValue1: "Guangzhou",
        name: "ExcludeGuangzhou",
      },
    ],
  },
],

PivotFilter options

OptionTypeDescription
fldnumberField index to filter on (required)
typestringFilter type from PivotFilterTypeValue (required)
idnumberUnique filter ID within the pivot table (required)
namestringFilter name
descriptionstringFilter description
stringValue1stringFirst value for caption/date filters
stringValue2stringSecond value for between filters
mpFldnumberMeasure field index for OLAP filters
evalOrdernumberEvaluation order
iMeasureHiernumberMeasure hierarchy
iMeasureFldnumberMeasure field

Available filter types (PivotFilterTypeValue)

CategoryValues
CaptionCAPTION_EQUAL, CAPTION_NOT_EQUAL, CAPTION_BEGINS_WITH, CAPTION_NOT_BEGINS_WITH, CAPTION_ENDS_WITH, CAPTION_NOT_ENDS_WITH, CAPTION_CONTAINS, CAPTION_NOT_CONTAINS, CAPTION_GREATER_THAN, CAPTION_GREATER_THAN_OR_EQUAL, CAPTION_LESS_THAN, CAPTION_LESS_THAN_OR_EQUAL, CAPTION_BETWEEN, CAPTION_NOT_BETWEEN
ValueVALUE_EQUAL, VALUE_NOT_EQUAL, VALUE_GREATER_THAN, VALUE_GREATER_THAN_OR_EQUAL, VALUE_LESS_THAN, VALUE_LESS_THAN_OR_EQUAL, VALUE_BETWEEN, VALUE_NOT_BETWEEN
DateDATE_EQUAL, DATE_NOT_EQUAL, DATE_OLDER_THAN, DATE_OLDER_THAN_OR_EQUAL, DATE_NEWER_THAN, DATE_NEWER_THAN_OR_EQUAL, DATE_BETWEEN, DATE_NOT_BETWEEN
RelativeTOMORROW, TODAY, YESTERDAY, NEXT_WEEK, THIS_WEEK, LAST_WEEK, NEXT_MONTH, THIS_MONTH, LAST_MONTH, NEXT_QUARTER, THIS_QUARTER, LAST_QUARTER, NEXT_YEAR, THIS_YEAR, LAST_YEAR, YEAR_TO_DATE
QuarterQ1, Q2, Q3, Q4
MonthM1 through M12
OtherUNKNOWN, COUNT, PERCENT, SUM

Conditional Formatting

Apply conditional formatting rules to pivot table areas:

pivotTables: [
  {
    source: "A1:C9",
    sourceSheet: "Data",
    location: "A3",
    rows: ["City"],
    columns: ["Category"],
    data: [
      {
        field: "Revenue",
        summarize: "sum",
        name: "Total Revenue",
        sortByTupleItems: [0],
      },
    ],
    pivotConditionalFormats: [
      {
        priority: 1,
        scope: "data",
        type: "all",
        pivotAreas: [
          {
            field: 2,
            type: "data",
            outline: true,
          },
        ],
      },
    ],
  },
],

Advanced Features

Page/Report Filters

Use pages to add report filter fields that appear above the pivot table:

pivotTables: [
  {
    source: "A1:D11",
    sourceSheet: "Data",
    location: "A3",
    rows: ["Region"],
    data: [{ field: "Sales", summarize: "sum" }],
    pages: ["Product"],
  },
],

Column Fields

Add columns to create cross-tabulations:

pivotTables: [
  {
    source: "A1:C9",
    sourceSheet: "Data",
    location: "A3",
    rows: ["City"],
    columns: ["Category"],
    data: [{ field: "Revenue", summarize: "sum" }],
  },
],

Pivot Hierarchies

Control field behavior with pivotHierarchies:

pivotTables: [
  {
    source: "A1:C9",
    sourceSheet: "Data",
    location: "A3",
    rows: ["City"],
    data: [{ field: "Revenue", summarize: "sum" }],
    pivotHierarchies: [
      {
        outline: true,
        dragToRow: true,
        dragToCol: true,
        showInFieldList: true,
        caption: "City",
      },
    ],
  },
],

Pivot Table Options Reference

OptionTypeDescription
sourcestringSource data range, e.g. "A1:C11"
sourceSheetstringSource sheet name (default: current sheet)
locationstringOutput start cell (default: "A3")
rowsstring[]Row field names
columnsstring[]Column field names
dataDataField[]Data field configurations
pagesstring[]Page/report filter field names
namestringPivot table name (default: "PivotTable1")
stylestringPivot style name (default: "PivotStyleLight16")
filtersPivotFilterOptions[]Pivot filters
pivotConditionalFormatsPivotConditionalFormat[]Conditional format rules for pivot areas
pivotHierarchiesPivotHierarchyOptions[]Pivot hierarchy configurations
calculatedItemsCalculatedItemOptions[]Calculated items
calculatedMembersCalculatedMemberOptions[]Calculated members (MDX)
chartFormatsChartFormatOptions[]Chart format associations
formatsPivotFormatOptions[]Pivot format areas
autoSortScopePivotAreaOptionsAuto sort scope definition
memberPropertiesMemberPropertyOptions[]Member properties per field
rowHierarchiesUsageHierarchyUsageOptions[]Row hierarchy usage
colHierarchiesUsageHierarchyUsageOptions[]Column hierarchy usage
dataOnRowsbooleanData fields on rows instead of columns
grandTotalCaptionstringGrand total caption text
errorCaptionstringError caption text
showErrorbooleanShow error messages
missingCaptionstringMissing caption text
showMissingbooleanShow missing items
pageStylestringPage style name
pivotTableStylestringCustom pivot table style name
tagstringTag string
showItemsbooleanShow items with no data
editDatabooleanEdit data in-place
disableFieldListbooleanDisable field list
showCalcMbrsbooleanShow calculated members
visualTotalsbooleanVisual totals
showMultipleLabelbooleanShow multiple labels
showDataDropDownbooleanShow data drop-down
showDrillbooleanShow drill indicators
printDrillbooleanPrint drill indicators
showMemberPropertyTipsbooleanShow member property tips
showDataTipsbooleanShow data tips
enableWizardbooleanEnable layout wizard
enableDrillbooleanEnable drill-down
enableFieldPropertiesbooleanEnable field properties
pageWrapnumberPage fields per row/column
pageOverThenDownbooleanPage layout over then down
subtotalHiddenItemsbooleanSubtotal hidden items
fieldPrintTitlesbooleanField print titles
mergeItembooleanMerge item labels
showDropZonesbooleanShow drop zones
showEmptyRowbooleanShow empty row
showEmptyColbooleanShow empty column
showHeadersbooleanShow headers
publishedbooleanPublished to server
gridDropZonesbooleanGrid drop zones
multipleFieldFiltersbooleanMultiple field filters
rowHeaderCaptionstringRow header caption
colHeaderCaptionstringColumn header caption
fieldListSortAscendingbooleanSort field list ascending
mdxSubqueriesbooleanMDX subqueries enabled
customListSortbooleanCustom list sort
Copyright © 2026