Skip to content

Commit a905bea

Browse files
update index.t.ds abd readme.md
1 parent d18fb91 commit a905bea

File tree

6 files changed

+215
-37
lines changed

6 files changed

+215
-37
lines changed

README.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,43 @@ Reverse engineered from Excel spreadsheet files as a project.
1313
# Installation
1414

1515
```shell
16-
npm install exceljs
16+
npm install @zurmokeeper/exceljs
1717
```
1818

19+
# V4.4.1 New Features!
20+
21+
Change Log:
22+
<ul>
23+
<li>
24+
Add nested columns feature. Thank you <a href="https://github.com/jeka1985">jeka1985</a>, Merged <a href="https://github.com/exceljs/exceljs/pull/1889"> PR1889</a>.
25+
26+
Code snippets:
27+
28+
// new api: worksheet.makeColumns()
29+
</li>
30+
<li>
31+
Add file encryption function.
32+
33+
Code snippets:
34+
await workbook.xlsx.writeFile(filename, {password: '123456'});
35+
</li>
36+
</ul>
37+
38+
# V4.4.0 New Features!
39+
40+
Change Log:
41+
<ul>
42+
<li>
43+
Add decryption of excel files with password encryption (Support frontend and backend)
44+
45+
Code snippets:
46+
47+
// read from a stream, decrypt excel files encrypted with password
48+
// const workbook = new Excel.Workbook();
49+
// await workbook.xlsx.readFile(filename, {password:'123456'});
50+
</li>
51+
</ul>
52+
1953
# New Features!
2054

2155
<ul>
@@ -742,6 +776,26 @@ const newCol3Values = [1,2,3,4,5];
742776
const newCol4Values = ['one', 'two', 'three', 'four', 'five'];
743777
worksheet.spliceColumns(3, 1, newCol3Values, newCol4Values);
744778

779+
// Nested columns
780+
// Also you can build nested columns
781+
worksheet.makeColumns([
782+
{
783+
id: 1,
784+
title: 'Some',
785+
},
786+
{id: 2, title: 'Qwe'},
787+
{id: 3, title: 'Foo'},
788+
{
789+
id: 4,
790+
title: 'Zoo',
791+
children: [
792+
{ id: 41, title: 'Zoo 1' },
793+
{ id: 42, title: 'Zoo 2' },
794+
{ id: 44, title: 'Zoo 3' },
795+
{ id: 45, title: 'Zoo 4' },
796+
]
797+
}
798+
]);
745799
```
746800

747801
## Rows[](#contents)<!-- Link generated with jump2header -->
@@ -2193,11 +2247,21 @@ await workbook.xlsx.load(data, {password:'123456'});
21932247
const workbook = createAndFillWorkbook();
21942248
await workbook.xlsx.writeFile(filename);
21952249

2250+
// write to a file, with password encryption
2251+
const workbook = createAndFillWorkbook();
2252+
await workbook.xlsx.writeFile(filename, {password: '123456'});
2253+
21962254
// write to a stream
21972255
await workbook.xlsx.write(stream);
21982256

2257+
// write to a stream, with password encryption
2258+
await workbook.xlsx.write(stream, {password: '123456'}));
2259+
21992260
// write to a new buffer
22002261
const buffer = await workbook.xlsx.writeBuffer();
2262+
2263+
// write to a new buffer, with password encryption
2264+
const buffer = await workbook.xlsx.writeBuffer({password: '123456'});
22012265
```
22022266

22032267
### CSV[](#contents)<!-- Link generated with jump2header -->

README_zh.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,43 @@
1111
# 安装
1212

1313
```shell
14-
npm install exceljs
14+
npm install @zurmokeeper/exceljs
1515
```
1616

17+
# V4.4.1 新的功能!
18+
19+
变更日志:
20+
<ul>
21+
<li>
22+
新增嵌套列功能(多表头). 感谢 <a href="https://github.com/jeka1985">jeka1985</a>, Merged <a href="https://github.com/exceljs/exceljs/pull/1889"> PR1889</a>.
23+
24+
Code snippets:
25+
26+
// new api: worksheet.makeColumns()
27+
</li>
28+
<li>
29+
新增导出加密Excel文件功能.
30+
31+
Code snippets:
32+
await workbook.xlsx.writeFile(filename, {password: '123456'});
33+
</li>
34+
</ul>
35+
36+
# V4.4.0 新的功能!
37+
38+
变更日志:
39+
<ul>
40+
<li>
41+
新增读取加密Excel的功能 (支持前端和后端(Node.js))
42+
43+
Code snippets:
44+
45+
// read from a stream, decrypt excel files encrypted with password
46+
// const workbook = new Excel.Workbook();
47+
// await workbook.xlsx.readFile(filename, {password:'123456'});
48+
</li>
49+
</ul>
50+
1751
# 新的功能!
1852

1953
<ul>
@@ -689,6 +723,26 @@ const newCol3Values = [1,2,3,4,5];
689723
const newCol4Values = ['one', 'two', 'three', 'four', 'five'];
690724
worksheet.spliceColumns(3, 1, newCol3Values, newCol4Values);
691725

726+
// 嵌套列
727+
// 使用这个API来构建嵌套列(实现多级表头)
728+
worksheet.makeColumns([
729+
{
730+
id: 1,
731+
title: 'Some',
732+
},
733+
{id: 2, title: 'Qwe'},
734+
{id: 3, title: 'Foo'},
735+
{
736+
id: 4,
737+
title: 'Zoo',
738+
children: [
739+
{ id: 41, title: 'Zoo 1' },
740+
{ id: 42, title: 'Zoo 2' },
741+
{ id: 44, title: 'Zoo 3' },
742+
{ id: 45, title: 'Zoo 4' },
743+
]
744+
}
745+
]);
692746
```
693747

694748
## [](#目录)<!-- Link generated with jump2header -->
@@ -2083,11 +2137,21 @@ await workbook.xlsx.load(data, {password:'123456'});
20832137
const workbook = createAndFillWorkbook();
20842138
await workbook.xlsx.writeFile(filename);
20852139

2140+
// 写入文件, 带密码保护的
2141+
const workbook = createAndFillWorkbook();
2142+
await workbook.xlsx.writeFile(filename, {password: '123456'});
2143+
20862144
// 写入流
20872145
await workbook.xlsx.write(stream);
20882146

2147+
// 写入流, 带密码保护的
2148+
await workbook.xlsx.write(stream, {password: '123456'}));
2149+
20892150
// 写入 buffer
20902151
const buffer = await workbook.xlsx.writeBuffer();
2152+
2153+
// 写入 buffer, 带密码保护的
2154+
const buffer = await workbook.xlsx.writeBuffer({password: '123456'});
20912155
```
20922156

20932157
### CSV[](#目录)<!-- Link generated with jump2header -->

index.d.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,15 +1163,43 @@ export interface Worksheet {
11631163
* Cut one or more columns (columns to the right are shifted left)
11641164
* and optionally insert more
11651165
*
1166-
* If column properties have been definde, they will be cut or moved accordingly
1166+
* If column properties have been define, they will be cut or moved accordingly
11671167
*
11681168
* Known Issue: If a splice causes any merged cells to move, the results may be unpredictable
11691169
*
1170-
* Also: If the worksheet has more rows than values in the colulmn inserts,
1170+
* Also: If the worksheet has more rows than values in the column inserts,
11711171
* the rows will still be shifted as if the values existed
11721172
*/
11731173
spliceColumns(start: number, count: number, ...insert: any[][]): void;
11741174

1175+
/**
1176+
* Generate nested columns
1177+
* Example:
1178+
*
1179+
* const headers = [
1180+
* {id: 1,title: 'name'},
1181+
{id: 2, title: 'Qwe'},
1182+
{id: 3, title: 'Foo'},
1183+
{
1184+
id: 4,
1185+
title: 'ABC',
1186+
children: [
1187+
{id: 41, title: 'Zoo 1'},
1188+
{id: 42, title: 'Zoo 2'},
1189+
{id: 44, title: 'Zoo 3'},
1190+
],
1191+
}]
1192+
*
1193+
* const workbook = new ExcelJS.Workbook();
1194+
* const worksheet = workbook.addWorksheet('Sheet1');
1195+
* worksheet.makeColumns(headers);
1196+
*
1197+
*
1198+
* Note: This API allows you to quickly build an excel with multiple table headers.
1199+
* TODO: Can you set the background color together?
1200+
*/
1201+
makeColumns(input: any[][]): any[][];
1202+
11751203
/**
11761204
* Add column headers and define column keys and widths.
11771205
*

lib/doc/worksheet.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,9 @@ class Worksheet {
924924
this.conditionalFormattings = value.conditionalFormattings;
925925
}
926926

927+
/**
928+
* @desc Generates a nested column
929+
*/
927930
makeColumns(input) {
928931
const flatter = new ColumnFlatter(input);
929932
const merges = flatter.getMerges();

lib/utils/column-flatter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const colCache = require('./col-cache');
44
* ColumnFlatter is a helper class to create sheets with nested columns.
55
*
66
* Based on following concepts
7-
* - Walk throught nested input structure to build flat list and tree meta information
7+
* - Walk through nested input structure to build flat list and tree meta information
88
* - Use "leaf" columns as physical cols and "branch" as merge-slots
99
* - Generate cell matrix and merge rules
1010
*/
@@ -46,7 +46,7 @@ class ColumnFlatter {
4646
}
4747

4848
/**
49-
* Walk throught tree input.
49+
* Walk through tree input.
5050
* Build flat columns list and aggregate column size (recursive children length sum)
5151
*/
5252
_getFlatList(input) {
@@ -158,7 +158,7 @@ class ColumnFlatter {
158158
/**
159159
* Calculates horizontal merge rules
160160
*
161-
* Walks width-throught rows collecting ranges with cell index and its recursive size
161+
* Walks width-through rows collecting ranges with cell index and its recursive size
162162
*/
163163
_calcHorizontalMerges() {
164164
const res = [];
@@ -184,7 +184,7 @@ class ColumnFlatter {
184184
/**
185185
* Calculates vertical merge rules
186186
*
187-
* Walks deep-throught rows looking for non-empty cell in row
187+
* Walks deep-through rows looking for non-empty cell in row
188188
*/
189189
_calcVerticalMerges() {
190190
const depth = this._rows.length - 1;

spec/integration/pr/test-pr-1899.spec.js

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ describe('pull request 1899', () => {
66
it('pull request 1899- Support nested columns feature', async () => {
77
async function test() {
88
const workbook = new ExcelJS.Workbook();
9-
// const worksheet = workbook.addWorksheet('sheet');
10-
const worksheet = workbook.addWorksheet('sheet', {
9+
const worksheet = workbook.addWorksheet('Sheet1', {
1110
// properties: {defaultColWidth: 25},
12-
views: [{state: 'frozen', xSplit: 0, ySplit: 3}], // 冻结第1行和第二行
11+
views: [{state: 'frozen', xSplit: 0, ySplit: 2}], // 冻结第1行和第二行
1312
});
1413

1514
worksheet.makeColumns([
@@ -26,14 +25,6 @@ describe('pull request 1899', () => {
2625
{id: 41, title: 'Zoo 1'},
2726
{id: 42, title: 'Zoo 2'},
2827
{id: 44, title: 'Zoo 3'},
29-
{
30-
id: 45,
31-
title: 'Zoo 4',
32-
children: [
33-
{id: 451, title: 'Zoo 3XXXX'},
34-
{id: 452, title: 'Zoo 3XXXX1232'},
35-
],
36-
},
3728
],
3829
},
3930
{
@@ -48,23 +39,7 @@ describe('pull request 1899', () => {
4839
{id: 6, title: 'Foo123213'},
4940
]);
5041
const data = [
51-
[
52-
1,
53-
'electron',
54-
'DOB',
55-
'DOB',
56-
'DOB',
57-
'DOB',
58-
'DOB',
59-
'DOB',
60-
'DOB',
61-
'DOB',
62-
'DOB',
63-
'DOB',
64-
'DOB',
65-
'DOB',
66-
],
67-
[null, null, null, null, null, 'DOB'],
42+
[1, 2, 3, null, null, 'DOB'],
6843
[1, 'electron', 'DOB'],
6944
[1, 'electron', 'DOB'],
7045
[1, 'electron', 'DOB'],
@@ -82,6 +57,50 @@ describe('pull request 1899', () => {
8257

8358
await test();
8459

85-
// expect(error).to.be.an('error');
60+
const workbookReader = new ExcelJS.Workbook();
61+
await workbookReader.xlsx.readFile(TEST_1899_XLSX_FILE_NAME);
62+
const worksheetReader = workbookReader.getWorksheet('Sheet1');
63+
64+
const actualRows = worksheetReader.getSheetValues();
65+
66+
// TODO: Why is the first data always null
67+
const expectedRows = [
68+
null,
69+
[
70+
null,
71+
'姓名',
72+
'Qwe',
73+
'Foo',
74+
'基础信息',
75+
'基础信息',
76+
'基础信息',
77+
'Zoo1',
78+
'Zoo1',
79+
'Zoo1',
80+
'Foo123213',
81+
],
82+
[
83+
null,
84+
'姓名',
85+
'Qwe',
86+
'Foo',
87+
'Zoo 1',
88+
'Zoo 2',
89+
'Zoo 3',
90+
'Zoo 51',
91+
'Zoo 52',
92+
'Zoo 53',
93+
'Foo123213',
94+
],
95+
[null, 1, 2, 3, null, null, 'DOB'],
96+
[null, 1, 'electron', 'DOB'],
97+
[null, 1, 'electron', 'DOB'],
98+
[null, 1, 'electron', 'DOB'],
99+
[null, 1, 'electron', 'DOB'],
100+
[null, 1, 'electron', 'DOB'],
101+
[null, 1, 'electron', 'DOB'],
102+
[null, 1, 'electron', 'DOB'],
103+
];
104+
expect(JSON.stringify(actualRows)).to.equal(JSON.stringify(expectedRows));
86105
});
87106
});

0 commit comments

Comments
 (0)