excellentexport 3.9.11 → 3.9.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,71 +1,163 @@
1
-
2
- import 'expect-puppeteer';
3
-
4
- import ExcellentExport, { ConvertOptions, SheetOptions } from '../src/excellentexport';
5
-
6
-
7
- describe('convert() API', function() {
8
- describe('convert from HTML table', function() {
9
-
10
- beforeEach(() => {
11
- window.URL.createObjectURL = () => "blob:fake_URL";
12
-
13
- document.body.innerHTML = '';
14
- const element = document.createElement("div");
15
- element.innerHTML =
16
- '<table id="sometable"><tr><th>first</th><th>second</th></tr><tr><td>1234</td><td>123.56</td></tr></table>' +
17
- '<a id="anchor">Link</a>';
18
-
19
- document.body.appendChild(element);
20
- });
21
-
22
- test('should create a XLSX from HTML table by #id', function() {
23
- const options = {
24
- anchor: 'anchor',
25
- filename: 'data_from_table',
26
- format: 'xlsx'
27
- } as ConvertOptions;
28
-
29
- const sheets = [
30
- {
31
- name: 'Sheet Name Here 1',
32
- from: {
33
- table: 'sometable'
34
- }
35
- }
36
- ] as SheetOptions[];
37
-
38
- const workbook = ExcellentExport.convert(options, sheets);
39
- expect(workbook).not.toBeNull();
40
-
41
- const anchor = document.getElementById('anchor') as HTMLAnchorElement;
42
- expect(anchor.href).not.toBeNull();
43
- expect(anchor.href).toMatch(/blob:/);
44
- });
45
-
46
- test('should create a XLSX from HTML table by DOM element', function() {
47
- const options = {
48
- anchor: document.getElementById('anchor'),
49
- filename: 'data_from_table',
50
- format: 'xlsx'
51
- } as ConvertOptions;
52
-
53
- const sheets = [
54
- {
55
- name: 'Sheet Name Here 1',
56
- from: {
57
- table: document.getElementById('sometable')
58
- }
59
- }
60
- ] as SheetOptions[];
61
-
62
- const workbook = ExcellentExport.convert(options, sheets);
63
- expect(workbook).not.toBeNull();
64
-
65
- const anchor = document.getElementById('anchor') as HTMLAnchorElement;
66
- expect(anchor.href).not.toBeNull();
67
- expect(anchor.href).toMatch(/blob:/);
68
- });
69
- });
70
- });
71
-
1
+
2
+ import { describe, expect, test, beforeEach, it, assert } from 'vitest'
3
+
4
+ import * as XLSX from 'xlsx';
5
+ import ExcellentExport, { ConvertOptions, SheetOptions } from '../src/excellentexport';
6
+
7
+
8
+ describe('convert() API', function() {
9
+ describe('convert from HTML table', function() {
10
+
11
+ beforeEach(() => {
12
+ window.URL.createObjectURL = () => "blob:fake_URL";
13
+
14
+ document.body.innerHTML = '';
15
+ const element = document.createElement("div");
16
+ element.innerHTML =
17
+ '<table id="sometable"><tr><th>first</th><th>second</th></tr><tr><td>1234</td><td>123.56</td></tr></table>' +
18
+ '<a id="anchor">Link</a>';
19
+
20
+ document.body.appendChild(element);
21
+ });
22
+
23
+ test('should create a XLSX from HTML table by #id', function() {
24
+ const options = {
25
+ anchor: 'anchor',
26
+ filename: 'data_from_table',
27
+ format: 'xlsx'
28
+ } as ConvertOptions;
29
+
30
+ const sheets = [
31
+ {
32
+ name: 'Sheet Name Here 1',
33
+ from: {
34
+ table: 'sometable'
35
+ }
36
+ }
37
+ ] as SheetOptions[];
38
+
39
+ const workbook = ExcellentExport.convert(options, sheets);
40
+ expect(workbook).not.toBeNull();
41
+
42
+ const anchor = document.getElementById('anchor') as HTMLAnchorElement;
43
+ expect(anchor.href).not.toBeNull();
44
+ expect(anchor.href).toMatch(/blob:/);
45
+ });
46
+
47
+ test('should create a XLSX from HTML table by DOM element', function() {
48
+ const options = {
49
+ anchor: document.getElementById('anchor'),
50
+ filename: 'data_from_table',
51
+ format: 'xlsx'
52
+ } as ConvertOptions;
53
+
54
+ const sheets = [
55
+ {
56
+ name: 'Sheet Name Here 1',
57
+ from: {
58
+ table: document.getElementById('sometable')
59
+ }
60
+ }
61
+ ] as SheetOptions[];
62
+
63
+ const workbook = ExcellentExport.convert(options, sheets);
64
+ expect(workbook).not.toBeNull();
65
+
66
+ const anchor = document.getElementById('anchor') as HTMLAnchorElement;
67
+ expect(anchor.href).not.toBeNull();
68
+ expect(anchor.href).toMatch(/blob:/);
69
+ });
70
+ });
71
+
72
+ describe('convert from HTML table with colspan and rowspan', function() {
73
+
74
+ beforeEach(() => {
75
+ window.URL.createObjectURL = () => "blob:fake_URL";
76
+ document.body.innerHTML = '';
77
+ const div = document.createElement('div');
78
+ div.innerHTML = '<a id="anchor">Link</a>';
79
+ document.body.appendChild(div);
80
+ });
81
+
82
+ function buildWorksheet(tableHtml: string): XLSX.WorkSheet {
83
+ const div = document.createElement('div');
84
+ div.id = 'wrapper';
85
+ div.innerHTML = tableHtml;
86
+ document.body.appendChild(div);
87
+
88
+ const wbBinary = ExcellentExport.convert(
89
+ { anchor: 'anchor', filename: 'test', format: 'xlsx' } as ConvertOptions,
90
+ [{ name: 'Sheet1', from: { table: div.querySelector('table') as HTMLTableElement } }] as SheetOptions[]
91
+ );
92
+
93
+ const wb = XLSX.read(wbBinary, { type: 'binary' });
94
+ return wb.Sheets['Sheet1'];
95
+ }
96
+
97
+ test('should produce merged cells for colspan=2', function() {
98
+ const ws = buildWorksheet(
99
+ '<table>' +
100
+ '<tr><td colspan="2">Header</td></tr>' +
101
+ '<tr><td>A</td><td>B</td></tr>' +
102
+ '</table>'
103
+ );
104
+
105
+ // Cell A1 should contain "Header"
106
+ expect(ws['A1'].v).toBe('Header');
107
+ // Merged region should cover A1:B1
108
+ expect(ws['!merges']).toBeDefined();
109
+ expect(ws['!merges']).toHaveLength(1);
110
+ expect(ws['!merges']![0]).toEqual({ s: { r: 0, c: 0 }, e: { r: 0, c: 1 } });
111
+ });
112
+
113
+ test('should produce merged cells for rowspan=2', function() {
114
+ const ws = buildWorksheet(
115
+ '<table>' +
116
+ '<tr><td rowspan="2">Side</td><td>Top</td></tr>' +
117
+ '<tr><td>Bottom</td></tr>' +
118
+ '</table>'
119
+ );
120
+
121
+ expect(ws['A1'].v).toBe('Side');
122
+ expect(ws['B1'].v).toBe('Top');
123
+ expect(ws['B2'].v).toBe('Bottom');
124
+ expect(ws['!merges']).toBeDefined();
125
+ expect(ws['!merges']).toHaveLength(1);
126
+ expect(ws['!merges']![0]).toEqual({ s: { r: 0, c: 0 }, e: { r: 1, c: 0 } });
127
+ });
128
+
129
+ test('should produce merged cells for combined colspan=2 rowspan=2', function() {
130
+ const ws = buildWorksheet(
131
+ '<table>' +
132
+ '<tr><td colspan="2" rowspan="2">Big</td><td>R0C2</td></tr>' +
133
+ '<tr><td>R1C2</td></tr>' +
134
+ '<tr><td>R2C0</td><td>R2C1</td><td>R2C2</td></tr>' +
135
+ '</table>'
136
+ );
137
+
138
+ expect(ws['A1'].v).toBe('Big');
139
+ expect(ws['C1'].v).toBe('R0C2');
140
+ expect(ws['C2'].v).toBe('R1C2');
141
+ expect(ws['A3'].v).toBe('R2C0');
142
+ expect(ws['!merges']).toBeDefined();
143
+ expect(ws['!merges']).toHaveLength(1);
144
+ expect(ws['!merges']![0]).toEqual({ s: { r: 0, c: 0 }, e: { r: 1, c: 1 } });
145
+ });
146
+
147
+ test('should produce no merges for a table without spans', function() {
148
+ const ws = buildWorksheet(
149
+ '<table>' +
150
+ '<tr><td>A</td><td>B</td></tr>' +
151
+ '<tr><td>C</td><td>D</td></tr>' +
152
+ '</table>'
153
+ );
154
+
155
+ expect(ws['A1'].v).toBe('A');
156
+ expect(ws['B2'].v).toBe('D');
157
+ // No merges
158
+ const merges = ws['!merges'];
159
+ expect(merges ?? []).toHaveLength(0);
160
+ });
161
+ });
162
+ });
163
+
@@ -1,56 +1,56 @@
1
- const assert = require('assert');
2
-
3
- import ExcellentExport, { ConvertOptions, SheetOptions } from '../src/excellentexport';
4
- import { PredefinedFormat } from '../src/format';
5
-
6
-
7
- describe('convert() API with column formats', function() {
8
-
9
- beforeEach(() => {
10
- window.URL.createObjectURL = () => "blob:fake_URL";
11
-
12
- document.body.innerHTML = '';
13
- const element = document.createElement("div");
14
- element.innerHTML = '<a id="anchor">Link</a>';
15
-
16
- document.body.appendChild(element);
17
- });
18
-
19
- it('should create a XLSX with types', function() {
20
- const options = {
21
- anchor: 'anchor',
22
- filename: 'data_from_array',
23
- format: 'xlsx'
24
- } as ConvertOptions;
25
-
26
- const sheets = [
27
- {
28
- name: 'People',
29
- from: {
30
- array: [
31
- ["ID", "Name", "Birthdate", "Active", "Salary"],
32
- [11, "John", "1980-01-01", true, 1000.98],
33
- [22, "Mary", "1985-02-02", false, 2000.88],
34
- [33, "Peter", "1990-03-03", true, 3000.32],
35
- ]
36
- },
37
- formats: [
38
- { range: 'A2:A10', format: PredefinedFormat.INTEGER },
39
- { range: 'C2:C10', format: PredefinedFormat.DATE },
40
- { range: 'D2:D10', format: PredefinedFormat.BOOLEAN },
41
- { range: 'E2:E10', format: PredefinedFormat.DECIMAL },
42
- ]
43
- },
44
-
45
- ] as SheetOptions[];
46
-
47
- const workbook = ExcellentExport.convert(options, sheets);
48
-
49
- assert.ok(workbook, 'Result must not be null');
50
-
51
- const anchor = document.getElementById('anchor') as HTMLAnchorElement;
52
- assert.ok(anchor.href, 'Element must have href');
53
- assert.ok(anchor.href.indexOf('blob:') === 0, 'Element href myst be a blob:');
54
- });
55
- });
56
-
1
+ import { describe, expect, test, beforeEach, it, assert } from 'vitest'
2
+
3
+ import ExcellentExport, { ConvertOptions, SheetOptions } from '../src/excellentexport';
4
+ import { PredefinedFormat } from '../src/format';
5
+
6
+
7
+ describe('convert() API with column formats', function() {
8
+
9
+ beforeEach(() => {
10
+ window.URL.createObjectURL = () => "blob:fake_URL";
11
+
12
+ document.body.innerHTML = '';
13
+ const element = document.createElement("div");
14
+ element.innerHTML = '<a id="anchor">Link</a>';
15
+
16
+ document.body.appendChild(element);
17
+ });
18
+
19
+ it('should create a XLSX with types', function() {
20
+ const options = {
21
+ anchor: 'anchor',
22
+ filename: 'data_from_array',
23
+ format: 'xlsx'
24
+ } as ConvertOptions;
25
+
26
+ const sheets = [
27
+ {
28
+ name: 'People',
29
+ from: {
30
+ array: [
31
+ ["ID", "Name", "Birthdate", "Active", "Salary"],
32
+ [11, "John", "1980-01-01", true, 1000.98],
33
+ [22, "Mary", "1985-02-02", false, 2000.88],
34
+ [33, "Peter", "1990-03-03", true, 3000.32],
35
+ ]
36
+ },
37
+ formats: [
38
+ { range: 'A2:A10', format: PredefinedFormat.INTEGER },
39
+ { range: 'C2:C10', format: PredefinedFormat.DATE },
40
+ { range: 'D2:D10', format: PredefinedFormat.BOOLEAN },
41
+ { range: 'E2:E10', format: PredefinedFormat.DECIMAL },
42
+ ]
43
+ },
44
+
45
+ ] as SheetOptions[];
46
+
47
+ const workbook = ExcellentExport.convert(options, sheets);
48
+
49
+ assert.ok(workbook, 'Result must not be null');
50
+
51
+ const anchor = document.getElementById('anchor') as HTMLAnchorElement;
52
+ assert.ok(anchor.href, 'Element must have href');
53
+ assert.ok(anchor.href.indexOf('blob:') === 0, 'Element href myst be a blob:');
54
+ });
55
+ });
56
+
@@ -1,59 +1,60 @@
1
- const assert = require('assert');
2
-
3
- import ExcellentExport, { ConvertOptions, SheetOptions } from '../src/excellentexport';
4
-
5
-
6
- describe('convert() API', function() {
7
- describe('convert from array', function() {
8
-
9
- beforeEach(() => {
10
- window.URL.createObjectURL = () => "blob:fake_URL";
11
-
12
- document.body.innerHTML = '';
13
- const element = document.createElement("div");
14
- element.innerHTML = '<a id="anchor">Link</a>';
15
-
16
- document.body.appendChild(element);
17
- });
18
-
19
- it('should create a XLSX from array', function() {
20
- const options = {
21
- anchor: 'anchor',
22
- filename: 'data_from_array',
23
- format: 'xlsx'
24
- } as ConvertOptions;
25
-
26
- const sheets = [
27
- {
28
- name: 'Sheet Name Here 1',
29
- from: {
30
- array: [
31
- [1, 2, 3],
32
- ['hello', '2200', 'bye'],
33
- ['quo"te', 'dobl"e qu"ote', 'singl\'e quote']
34
- ]
35
- }
36
- },
37
- {
38
- name: 'Sheet Number 2',
39
- from: {
40
- array: [
41
- [6666, 7777, 8888],
42
- ['lorem', 'ipsum', 'dolor']
43
- ]
44
- }
45
- },
46
-
47
- ] as SheetOptions[];
48
-
49
- const workbook = ExcellentExport.convert(options, sheets);
50
-
51
- assert.ok(workbook, 'Result must not be null');
52
-
53
- const anchor = document.getElementById('anchor') as HTMLAnchorElement;
54
- assert.ok(anchor.href, 'Element must have href');
55
- assert.ok(anchor.href.indexOf('blob:') === 0, 'Element href myst be a blob:');
56
- });
57
- });
58
- });
59
-
1
+ import { describe, expect, test, beforeEach, it, assert } from 'vitest'
2
+
3
+ import ExcellentExport, { ConvertOptions, SheetOptions } from '../src/excellentexport';
4
+
5
+
6
+
7
+ describe('convert() API', function() {
8
+ describe('convert from array', function() {
9
+
10
+ beforeEach(() => {
11
+ window.URL.createObjectURL = () => "blob:fake_URL";
12
+
13
+ document.body.innerHTML = '';
14
+ const element = document.createElement("div");
15
+ element.innerHTML = '<a id="anchor">Link</a>';
16
+
17
+ document.body.appendChild(element);
18
+ });
19
+
20
+ it('should create a XLSX from array', function() {
21
+ const options = {
22
+ anchor: 'anchor',
23
+ filename: 'data_from_array',
24
+ format: 'xlsx'
25
+ } as ConvertOptions;
26
+
27
+ const sheets = [
28
+ {
29
+ name: 'Sheet Name Here 1',
30
+ from: {
31
+ array: [
32
+ [1, 2, 3],
33
+ ['hello', '2200', 'bye'],
34
+ ['quo"te', 'dobl"e qu"ote', 'singl\'e quote']
35
+ ]
36
+ }
37
+ },
38
+ {
39
+ name: 'Sheet Number 2',
40
+ from: {
41
+ array: [
42
+ [6666, 7777, 8888],
43
+ ['lorem', 'ipsum', 'dolor']
44
+ ]
45
+ }
46
+ },
47
+
48
+ ] as SheetOptions[];
49
+
50
+ const workbook = ExcellentExport.convert(options, sheets);
51
+
52
+ assert.ok(workbook, 'Result must not be null');
53
+
54
+ const anchor = document.getElementById('anchor') as HTMLAnchorElement;
55
+ assert.ok(anchor.href, 'Element must have href');
56
+ assert.ok(anchor.href.indexOf('blob:') === 0, 'Element href myst be a blob:');
57
+ });
58
+ });
59
+ });
60
+
@@ -1,74 +1,74 @@
1
- const assert = require('assert');
2
-
3
- import ExcellentExport, { ConvertOptions } from '../src/excellentexport';
4
-
5
-
6
- describe('Fix data', function() {
7
- beforeEach(() => {
8
- window.URL.createObjectURL = () => "blob:fake_URL";
9
-
10
- document.body.innerHTML = '';
11
- const element = document.createElement("div");
12
- element.innerHTML = '<a id="anchor">Link</a>';
13
-
14
- document.body.appendChild(element);
15
- });
16
-
17
- it('should fix values', function() {
18
- const options = {
19
- anchor: 'anchor',
20
- filename: 'data_from_array',
21
- format: 'xlsx'
22
- } as ConvertOptions;
23
-
24
- const sheets = [
25
- {
26
- name: 'Sheet Name Here 1',
27
- from: {
28
- array: [
29
- ['hello', '<td>hello</td>', 'bye'],
30
- ]
31
- },
32
- fixValue: (value, row, col) => {
33
- let v = value.replace(/<br>/gi, "\n");
34
- let strippedString = v.replace(/(<([^>]+)>)/gi, "");
35
- return strippedString;
36
- }
37
- }
38
- ];
39
-
40
- const workbook = ExcellentExport.convert(options, sheets);
41
- assert.ok(workbook, 'Result must not be null');
42
- });
43
-
44
- it('should process the whole array', function() {
45
- const options = {
46
- anchor: 'anchor',
47
- filename: 'data_from_array',
48
- format: 'xlsx'
49
- } as ConvertOptions;
50
-
51
- const sheets = [
52
- {
53
- name: 'Sheet Name Here 1',
54
- from: {
55
- array: [
56
- ['hello', '<td>hello</td>', 'bye'],
57
- ]
58
- },
59
- fixData: (array) => {
60
- return array.map(r => {
61
- return r.map(v => {
62
- return "fixed-" + v;
63
- })
64
- });
65
- }
66
- }
67
- ];
68
-
69
- const workbook = ExcellentExport.convert(options, sheets);
70
- assert.ok(workbook, 'Result must not be null');
71
- });
72
-
73
- });
74
-
1
+ import { describe, expect, test, beforeEach, it, assert } from 'vitest'
2
+
3
+ import ExcellentExport, { ConvertOptions } from '../src/excellentexport';
4
+
5
+
6
+ describe('Fix data', function() {
7
+ beforeEach(() => {
8
+ window.URL.createObjectURL = () => "blob:fake_URL";
9
+
10
+ document.body.innerHTML = '';
11
+ const element = document.createElement("div");
12
+ element.innerHTML = '<a id="anchor">Link</a>';
13
+
14
+ document.body.appendChild(element);
15
+ });
16
+
17
+ it('should fix values', function() {
18
+ const options = {
19
+ anchor: 'anchor',
20
+ filename: 'data_from_array',
21
+ format: 'xlsx'
22
+ } as ConvertOptions;
23
+
24
+ const sheets = [
25
+ {
26
+ name: 'Sheet Name Here 1',
27
+ from: {
28
+ array: [
29
+ ['hello', '<td>hello</td>', 'bye'],
30
+ ]
31
+ },
32
+ fixValue: (value: any, row: number, col: number) => {
33
+ let v = value.replace(/<br>/gi, "\n");
34
+ let strippedString = v.replace(/(<([^>]+)>)/gi, "");
35
+ return strippedString;
36
+ }
37
+ }
38
+ ];
39
+
40
+ const workbook = ExcellentExport.convert(options, sheets);
41
+ assert.ok(workbook, 'Result must not be null');
42
+ });
43
+
44
+ it('should process the whole array', function() {
45
+ const options = {
46
+ anchor: 'anchor',
47
+ filename: 'data_from_array',
48
+ format: 'xlsx'
49
+ } as ConvertOptions;
50
+
51
+ const sheets = [
52
+ {
53
+ name: 'Sheet Name Here 1',
54
+ from: {
55
+ array: [
56
+ ['hello', '<td>hello</td>', 'bye'],
57
+ ]
58
+ },
59
+ fixArray: (array: any[][]) => {
60
+ return array.map((r: any[]) => {
61
+ return r.map((v: any) => {
62
+ return "fixed-" + v;
63
+ })
64
+ });
65
+ }
66
+ }
67
+ ];
68
+
69
+ const workbook = ExcellentExport.convert(options, sheets);
70
+ assert.ok(workbook, 'Result must not be null');
71
+ });
72
+
73
+ });
74
+