@univerjs-prosheets-pivotfacadeinterfacesIfworkbooksheetspivotmixin

@univerjs-pro/sheets-pivot v0.5.1Docs


Interface: IFWorkbookSheetsPivotMixin

Methods

addPivotTable()

addPivotTable(
   sourceInfo, 
   positionType, 
anchorCellInfo): Promise<undefined | FPivotTable>

Parameters

ParameterTypeDescription
sourceInfoIUnitRangeName & { subUnitId: string; }The source data range info of the pivot table.
positionTypePositionTypewhether new a sheet or insert a pivot table to the existing sheet.
anchorCellInfoIPivotCellPositionInfoThe target cell info of the pivot table.

Returns

Promise<undefined | FPivotTable>

The added pivot table id.

Description

Add a pivot table to the Workbook.

Example

// should ensure the sheet range {0,0,8,6} is not empty
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fSheet = fWorkbook.getActiveSheet();
const subUnitId = fSheet.getSheetId()
const sheetName = fSheet.getSheetName();
const sourceInfo = {
    unitId,
    subUnitId,
    sheetName,
    range: {
        startRow: 0,
        endRow: 8,
        startColumn: 0,
        endColumn: 6
    }
}
const anchorCellInfo = {
    unitId,
    subUnitId,
    row: 0,
    col: 8
}
const fp = await fWorkbook.addPivotTable(sourceInfo, 'exiting', anchorCellInfo)
// the addPivotTable is async, you can add pivot fields after the pivot table is added
// in the future, we will support pivot table added event, you can add pivot fields in the event handler
setTimeout(function() {
    fp.addField(1, 2)
    fp.addField(1, 3)
}, 1000)

Defined in

packages/sheets-pivot/src/facade/f-workbook.ts:60


getPivotTableByCell()

getPivotTableByCell(
   unitId, 
   subUnitId, 
   row, 
   col): undefined | FPivotTable

Parameters

ParameterTypeDescription
unitIdstringThe unit id of workbook.
subUnitIdstringThe sheet id, which pivot table belongs to.
rownumberThe checked row.
colnumberThe checked column.

Returns

undefined | FPivotTable

The pivot table id or undefined.

Description

Get the pivot table id by the cell.

Defined in

packages/sheets-pivot/src/facade/f-workbook.ts:69