@univerjs-pro/sheets-pivot v0.5.1 • Docs
Interface: IFWorkbookSheetsPivotMixin
Methods
addPivotTable()
addPivotTable(
sourceInfo,
positionType,
anchorCellInfo): Promise<undefined | FPivotTable>
Parameters
Parameter | Type | Description |
---|---|---|
sourceInfo | IUnitRangeName & { subUnitId : string ; } | The source data range info of the pivot table. |
positionType | PositionType | whether new a sheet or insert a pivot table to the existing sheet. |
anchorCellInfo | IPivotCellPositionInfo | The 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
Parameter | Type | Description |
---|---|---|
unitId | string | The unit id of workbook. |
subUnitId | string | The sheet id, which pivot table belongs to. |
row | number | The checked row. |
col | number | The 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