Skip to content

Commit 5c3fe3c

Browse files
add addPivotTable readme.md
1 parent ae3fcd0 commit 5c3fe3c

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ To be clear, all contributions added to this library will be included in the lib
203203
<li><a href="#data-validations">Data Validations</a></li>
204204
<li><a href="#cell-comments">Cell Comments</a></li>
205205
<li><a href="#tables">Tables</a></li>
206+
<li><a href="#pivot-tables">PivotTables</a></li>
206207
<li><a href="#styles">Styles</a>
207208
<ul>
208209
<li><a href="#number-formats">Number Formats</a></li>
@@ -1540,7 +1541,33 @@ column.totalsRowResult = 10;
15401541
// commit the table changes into the sheet
15411542
table.commit();
15421543
```
1543-
1544+
## PivotTables[](#contents)<!-- Link generated with jump2header -->
1545+
## add pivot table to worksheet
1546+
```javascript
1547+
const worksheet1 = workbook.addWorksheet('Sheet1');
1548+
worksheet1.addRows([
1549+
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'],
1550+
['a1', 'b1', 'c1', 'd1', 'e1', 'f1', 4, 5],
1551+
['a1', 'b2', 'c1', 'd2', 'e1', 'f1', 4, 5],
1552+
['a2', 'b1', 'c2', 'd1', 'e2', 'f1', 14, 24],
1553+
['a2', 'b2', 'c2', 'd2', 'e2', 'f2', 24, 35],
1554+
['a3', 'b1', 'c3', 'd1', 'e3', 'f2', 34, 45],
1555+
['a3', 'b2', 'c3', 'd2', 'e3', 'f2', 44, 45],
1556+
]);
1557+
1558+
const worksheet2 = workbook.addWorksheet('Sheet2');
1559+
worksheet2.addPivotTable({
1560+
// Source of data: the entire sheet range is taken;
1561+
// akin to `worksheet1.getSheetValues()`.
1562+
sourceSheet: worksheet1,
1563+
// Pivot table fields: values indicate field names;
1564+
// they come from the first row in `worksheet1`.
1565+
rows: ['A', 'B', 'E'],
1566+
columns: ['C', 'D'],
1567+
values: ['H'],
1568+
metric: 'sum', // only 'sum' possible for now
1569+
});
1570+
```
15441571

15451572
## Styles[](#contents)<!-- Link generated with jump2header -->
15461573

README_zh.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ ws1.getCell('A1').value = { text: 'Sheet2', hyperlink: '#A1:B1' };
163163
<li><a href="#数据验证">数据验证</a></li>
164164
<li><a href="#单元格注释">单元格注释</a></li>
165165
<li><a href="#表格">表格</a></li>
166+
<li><a href="#透视表">透视表</a></li>
166167
<li><a href="#样式">样式</a>
167168
<ul>
168169
<li><a href="#数字格式">数字格式</a></li>
@@ -1477,6 +1478,33 @@ column.totalsRowResult = 10;
14771478
table.commit();
14781479
```
14791480

1481+
## 透视表[](#目录)<!-- Link generated with jump2header -->
1482+
## 新增透视表到工作表
1483+
```javascript
1484+
const worksheet1 = workbook.addWorksheet('Sheet1');
1485+
worksheet1.addRows([
1486+
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'],
1487+
['a1', 'b1', 'c1', 'd1', 'e1', 'f1', 4, 5],
1488+
['a1', 'b2', 'c1', 'd2', 'e1', 'f1', 4, 5],
1489+
['a2', 'b1', 'c2', 'd1', 'e2', 'f1', 14, 24],
1490+
['a2', 'b2', 'c2', 'd2', 'e2', 'f2', 24, 35],
1491+
['a3', 'b1', 'c3', 'd1', 'e3', 'f2', 34, 45],
1492+
['a3', 'b2', 'c3', 'd2', 'e3', 'f2', 44, 45],
1493+
]);
1494+
1495+
const worksheet2 = workbook.addWorksheet('Sheet2');
1496+
worksheet2.addPivotTable({
1497+
// Source of data: the entire sheet range is taken;
1498+
// akin to `worksheet1.getSheetValues()`.
1499+
sourceSheet: worksheet1,
1500+
// Pivot table fields: values indicate field names;
1501+
// they come from the first row in `worksheet1`.
1502+
rows: ['A', 'B', 'E'],
1503+
columns: ['C', 'D'],
1504+
values: ['H'],
1505+
metric: 'sum', // only 'sum' possible for now
1506+
});
1507+
```
14801508

14811509
## 样式[](#目录)<!-- Link generated with jump2header -->
14821510

0 commit comments

Comments
 (0)