You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
```js
worksheet.addPivotTable(configuration);
```
**Note:** Pivot table support is in its early stages with certain limitations, including:
- No support for reading xlsx documents with existing pivot tables (writing is supported).
- Pivot table configurations must consist of 2 rows, 1 column, 1 value, and use the sum metric. The source data can have any number of columns and rows.
- Only one pivot table can be added.
## Pivot Tables[⬆](#contents)<!-- Link generated with jump2header -->
2552
+
2553
+
Add a pivot table to a Workbook without existing pivot tables.
2554
+
2555
+
```javascript
2556
+
worksheet.addPivotTable(configuration);
2557
+
```
2558
+
2559
+
**Note:** Pivot table support is in its early stages with certain limitations, including:
2560
+
2561
+
- No support for reading xlsx documents with existing pivot tables (writing is supported).
2562
+
- Pivot table configurations must consist of 2 rows, 1 column, 1 value, and use the sum metric. The source data can have any number of columns and rows.
2563
+
- Only one pivot table can be added.
2564
+
2565
+
### Add pivot table to worksheet[⬆](#contents)<!-- Link generated with jump2header -->
2566
+
2567
+
```javascript
2568
+
constworkbook=newExcel.Workbook();
2569
+
2570
+
constworksheet1=workbook.addWorksheet('Sheet1');
2571
+
worksheet1.addRows([
2572
+
['A', 'B', 'C', 'D', 'E'],
2573
+
['a1', 'b1', 'c1', 4, 5],
2574
+
['a1', 'b2', 'c1', 4, 5],
2575
+
['a2', 'b1', 'c2', 14, 24],
2576
+
['a2', 'b2', 'c2', 24, 35],
2577
+
['a3', 'b1', 'c3', 34, 45],
2578
+
['a3', 'b2', 'c3', 44, 45],
2579
+
]);
2580
+
2581
+
constworksheet2=workbook.addWorksheet('Sheet2');
2582
+
worksheet2.addPivotTable({
2583
+
// Source data: entire sheet range
2584
+
sourceSheet: worksheet1,
2585
+
// Pivot table fields: via header row in `worksheet1`
2586
+
rows: ['A', 'B'], // Exactly 2 fields
2587
+
columns: ['C'], // Exactly 1 field
2588
+
values: ['E'], // Exactly 1 field
2589
+
metric:'sum', // Metric: 'sum' only
2590
+
});
2591
+
```
2592
+
2546
2593
# Browser[⬆](#contents)<!-- Link generated with jump2header -->
2547
2594
2548
2595
A portion of this library has been isolated and tested for use within a browser environment.
0 commit comments