Excel.PivotLayout class
Represents the visual layout of the PivotTable.
- Extends
Remarks
Properties
context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
layout |
This property indicates the PivotLayoutType of all fields on the PivotTable. If fields have different states, this will be null. |
show |
Specifies if the PivotTable report shows grand totals for columns. |
show |
Specifies if the PivotTable report shows grand totals for rows. |
subtotal |
This property indicates the |
Methods
get |
Returns the range where the PivotTable's column labels reside. |
get |
Returns the range where the PivotTable's data values reside. |
get |
Returns the range of the PivotTable's filter area. |
get |
Returns the range the PivotTable exists on, excluding the filter area. |
get |
Returns the range where the PivotTable's row labels reside. |
load(options) | Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
set(properties, options) | Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type. |
set(properties) | Sets multiple properties on the object at the same time, based on an existing loaded object. |
toJSON() | Overrides the JavaScript |
Property Details
context
The request context associated with the object. This connects the add-in's process to the Office host application's process.
context: RequestContext;
Property Value
layoutType
This property indicates the PivotLayoutType of all fields on the PivotTable. If fields have different states, this will be null.
layoutType: Excel.PivotLayoutType | "Compact" | "Tabular" | "Outline";
Property Value
Excel.PivotLayoutType | "Compact" | "Tabular" | "Outline"
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-pivotlayout.yaml
await Excel.run(async (context) => {
// Change the PivotLayout.type to a new type.
const pivotTable = context.workbook.worksheets.getActiveWorksheet().pivotTables.getItem("Farm Sales");
pivotTable.layout.load("layoutType");
await context.sync();
// Cycle between the three layout types.
if (pivotTable.layout.layoutType === "Compact") {
pivotTable.layout.layoutType = "Outline";
} else if (pivotTable.layout.layoutType === "Outline") {
pivotTable.layout.layoutType = "Tabular";
} else {
pivotTable.layout.layoutType = "Compact";
}
await context.sync();
console.log("Pivot layout is now " + pivotTable.layout.layoutType);
});
showColumnGrandTotals
Specifies if the PivotTable report shows grand totals for columns.
showColumnGrandTotals: boolean;
Property Value
boolean
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-pivotlayout.yaml
await Excel.run(async (context) => {
// Turn the grand totals on and off for the rows and columns.
const pivotTable = context.workbook.pivotTables.getItem("Farm Sales");
const pivotLayout = pivotTable.layout;
pivotLayout.load(["showRowGrandTotals", "showColumnGrandTotals"]);
await context.sync();
let showColumnTotals = !pivotLayout.showColumnGrandTotals;
let showRowTotals = !pivotLayout.showRowGrandTotals;
console.log(`Show column grand totals? - ${showColumnTotals}`);
console.log(`Show row grand totals? - ${showRowTotals}`);
pivotLayout.showColumnGrandTotals = showColumnTotals;
pivotLayout.showRowGrandTotals = showRowTotals;
await context.sync();
});
showRowGrandTotals
Specifies if the PivotTable report shows grand totals for rows.
showRowGrandTotals: boolean;
Property Value
boolean
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-pivotlayout.yaml
await Excel.run(async (context) => {
// Turn the grand totals on and off for the rows and columns.
const pivotTable = context.workbook.pivotTables.getItem("Farm Sales");
const pivotLayout = pivotTable.layout;
pivotLayout.load(["showRowGrandTotals", "showColumnGrandTotals"]);
await context.sync();
let showColumnTotals = !pivotLayout.showColumnGrandTotals;
let showRowTotals = !pivotLayout.showRowGrandTotals;
console.log(`Show column grand totals? - ${showColumnTotals}`);
console.log(`Show row grand totals? - ${showRowTotals}`);
pivotLayout.showColumnGrandTotals = showColumnTotals;
pivotLayout.showRowGrandTotals = showRowTotals;
await context.sync();
});
subtotalLocation
This property indicates the SubtotalLocationType
of all fields on the PivotTable. If fields have different states, this will be null
.
subtotalLocation: Excel.SubtotalLocationType | "AtTop" | "AtBottom" | "Off";
Property Value
Excel.SubtotalLocationType | "AtTop" | "AtBottom" | "Off"
Remarks
Method Details
getColumnLabelRange()
Returns the range where the PivotTable's column labels reside.
getColumnLabelRange(): Excel.Range;
Returns
Remarks
getDataBodyRange()
Returns the range where the PivotTable's data values reside.
getDataBodyRange(): Excel.Range;
Returns
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-filters-and-summaries.yaml
await Excel.run(async (context) => {
const pivotTable = context.workbook.worksheets.getActiveWorksheet().pivotTables.getItem("Farm Sales");
// The layout controls the ranges used by the PivotTable.
const range = pivotTable.layout.getDataBodyRange();
// Get all the data hierarchy totals.
const grandTotalRange = range.getLastRow();
grandTotalRange.load("address");
await context.sync();
// Use the wholesale and farm sale totals to make a final sum.
const masterTotalRange = context.workbook.worksheets.getActiveWorksheet().getRange("B27:C27");
masterTotalRange.formulas = [["All Crates", "=SUM(" + grandTotalRange.address + ")"]];
await context.sync();
});
getFilterAxisRange()
Returns the range of the PivotTable's filter area.
getFilterAxisRange(): Excel.Range;
Returns
Remarks
getRange()
Returns the range the PivotTable exists on, excluding the filter area.
getRange(): Excel.Range;
Returns
Remarks
getRowLabelRange()
Returns the range where the PivotTable's row labels reside.
getRowLabelRange(): Excel.Range;
Returns
Remarks
load(options)
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(options?: Excel.Interfaces.PivotLayoutLoadOptions): Excel.PivotLayout;
Parameters
Provides options for which properties of the object to load.
Returns
load(propertyNames)
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(propertyNames?: string | string[]): Excel.PivotLayout;
Parameters
- propertyNames
-
string | string[]
A comma-delimited string or an array of strings that specify the properties to load.
Returns
load(propertyNamesAndPaths)
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Excel.PivotLayout;
Parameters
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select
is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand
is a comma-delimited string that specifies the navigation properties to load.
Returns
set(properties, options)
Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.
set(properties: Interfaces.PivotLayoutUpdateData, options?: OfficeExtension.UpdateOptions): void;
Parameters
- properties
- Excel.Interfaces.PivotLayoutUpdateData
A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.
- options
- OfficeExtension.UpdateOptions
Provides an option to suppress errors if the properties object tries to set any read-only properties.
Returns
void
set(properties)
Sets multiple properties on the object at the same time, based on an existing loaded object.
set(properties: Excel.PivotLayout): void;
Parameters
- properties
- Excel.PivotLayout
Returns
void
toJSON()
Overrides the JavaScript toJSON()
method in order to provide more useful output when an API object is passed to JSON.stringify()
. (JSON.stringify
, in turn, calls the toJSON
method of the object that is passed to it.) Whereas the original Excel.PivotLayout
object is an API object, the toJSON
method returns a plain JavaScript object (typed as Excel.Interfaces.PivotLayoutData
) that contains shallow copies of any loaded child properties from the original object.
toJSON(): Excel.Interfaces.PivotLayoutData;
Returns
Office Add-ins