excellentexport 3.9.9 → 3.9.10
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.
- package/.github/FUNDING.yml +1 -1
- package/.github/dependabot.yml +7 -7
- package/.github/workflows/webpack.yml +2 -2
- package/LICENSE.txt +21 -21
- package/README.md +5 -0
- package/bower.json +32 -32
- package/dist/excellentexport.d.ts +1 -1
- package/dist/excellentexport.js +1 -1
- package/index.bigtable.html +55 -55
- package/index.filters.html +63 -63
- package/index.html +127 -127
- package/index.noanchor.html +31 -31
- package/index.rtl.html +68 -68
- package/jest.config.ts +203 -203
- package/package.json +46 -45
- package/src/excellentexport.ts +2 -2
- package/src/utils.ts +144 -144
- package/test/convert-filters.test.ts +70 -70
- package/test/convert-table.test.ts +71 -71
- package/test/fixdata.test.ts +74 -74
- package/test/utils.test.ts +29 -29
- package/test/utils_fixdata.test.ts +24 -24
- package/test/utils_removeColumns.test.ts +98 -98
- package/tsconfig.json +17 -17
package/src/utils.ts
CHANGED
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
|
|
2
|
-
export const b64toBlob = function (b64Data:string, contentType:string, sliceSize?:number): Blob {
|
|
3
|
-
// function taken from http://stackoverflow.com/a/16245768/2591950
|
|
4
|
-
// author Jeremy Banks http://stackoverflow.com/users/1114/jeremy-banks
|
|
5
|
-
contentType = contentType || '';
|
|
6
|
-
sliceSize = sliceSize || 512;
|
|
7
|
-
|
|
8
|
-
const byteCharacters = atob(b64Data);
|
|
9
|
-
const byteArrays = [];
|
|
10
|
-
|
|
11
|
-
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
|
|
12
|
-
const slice = byteCharacters.slice(offset, offset + sliceSize);
|
|
13
|
-
|
|
14
|
-
const byteNumbers = new Array(slice.length);
|
|
15
|
-
for (let i = 0; i < slice.length; i = i + 1) {
|
|
16
|
-
byteNumbers[i] = slice.charCodeAt(i);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const byteArray = new Uint8Array(byteNumbers);
|
|
20
|
-
|
|
21
|
-
byteArrays.push(byteArray);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return new Blob(byteArrays, {
|
|
25
|
-
type: contentType
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const templates = {excel: '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta name=ProgId content=Excel.Sheet> <meta name=Generator content="Microsoft Excel 11"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Convert a string to Base64.
|
|
33
|
-
*/
|
|
34
|
-
export const base64 = function(s:string) : string {
|
|
35
|
-
return btoa(unescape(encodeURIComponent(s)));
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const format = function(s:string, context:any) : string {
|
|
39
|
-
return s.replace(new RegExp("{(\\w+)}", "g"), function(m, p) {
|
|
40
|
-
return context[p] || "{" + p + "}";
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Get element by ID.
|
|
46
|
-
* @param {*} element
|
|
47
|
-
*/
|
|
48
|
-
export const getTable = function(element :(HTMLTableElement|string)) : HTMLTableElement {
|
|
49
|
-
if (typeof element === 'string') {
|
|
50
|
-
return document.getElementById(element) as HTMLTableElement;
|
|
51
|
-
}
|
|
52
|
-
return element;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Get element by ID.
|
|
57
|
-
* @param {*} element
|
|
58
|
-
*/
|
|
59
|
-
export const getAnchor = function(element :(HTMLAnchorElement|string)) : HTMLAnchorElement {
|
|
60
|
-
if (typeof element === 'string') {
|
|
61
|
-
return document.getElementById(element) as HTMLAnchorElement;
|
|
62
|
-
}
|
|
63
|
-
return element;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Encode a value for CSV.
|
|
68
|
-
* @param {*} value
|
|
69
|
-
*/
|
|
70
|
-
export const fixCSVField = function(value:string, csvDelimiter:string) : string {
|
|
71
|
-
let fixedValue = value;
|
|
72
|
-
const addQuotes = (value.indexOf(csvDelimiter) !== -1) || (value.indexOf('\r') !== -1) || (value.indexOf('\n') !== -1);
|
|
73
|
-
const replaceDoubleQuotes = (value.indexOf('"') !== -1);
|
|
74
|
-
|
|
75
|
-
if (replaceDoubleQuotes) {
|
|
76
|
-
fixedValue = fixedValue.replace(/"/g, '""');
|
|
77
|
-
}
|
|
78
|
-
if (addQuotes || replaceDoubleQuotes) {
|
|
79
|
-
fixedValue = '"' + fixedValue + '"';
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return fixedValue;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export const tableToArray = function(table:HTMLTableElement) : any[][] {
|
|
86
|
-
let tableInfo = Array.prototype.map.call(table.querySelectorAll('tr'), function(tr) {
|
|
87
|
-
return Array.prototype.map.call(tr.querySelectorAll('th,td'), function(td) {
|
|
88
|
-
return td.innerHTML;
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
return tableInfo;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export const tableToCSV = function(table:HTMLTableElement, csvDelimiter:string = ',', csvNewLine:string = '\n') : string {
|
|
95
|
-
let data = "";
|
|
96
|
-
for (let i = 0; i < table.rows.length; i=i+1) {
|
|
97
|
-
const row = table.rows[i];
|
|
98
|
-
for (let j = 0; j < row.cells.length; j=j+1) {
|
|
99
|
-
const col = row.cells[j];
|
|
100
|
-
data = data + (j ? csvDelimiter : '') + fixCSVField(col.textContent.trim(), csvDelimiter);
|
|
101
|
-
}
|
|
102
|
-
data = data + csvNewLine;
|
|
103
|
-
}
|
|
104
|
-
return data;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export const createDownloadLink = function(anchor:HTMLAnchorElement, base64data:string, exporttype:string, filename:string) : boolean {
|
|
108
|
-
if (window.navigator.msSaveBlob) {
|
|
109
|
-
const blob = b64toBlob(base64data, exporttype);
|
|
110
|
-
window.navigator.msSaveBlob(blob, filename);
|
|
111
|
-
return false;
|
|
112
|
-
} else if (window.URL.createObjectURL) {
|
|
113
|
-
const blob = b64toBlob(base64data, exporttype);
|
|
114
|
-
anchor.href = window.URL.createObjectURL(blob);
|
|
115
|
-
} else {
|
|
116
|
-
anchor.download = filename;
|
|
117
|
-
anchor.href = "data:" + exporttype + ";base64," + base64data;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Return true to allow the link to work
|
|
121
|
-
return true;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
// String to ArrayBuffer
|
|
125
|
-
export const string2ArrayBuffer = function (s:string): ArrayBuffer {
|
|
126
|
-
let buf = new ArrayBuffer(s.length);
|
|
127
|
-
let view = new Uint8Array(buf);
|
|
128
|
-
for (let i=0; i !== s.length; ++i) {
|
|
129
|
-
view[i] = s.charCodeAt(i) & 0xFF;
|
|
130
|
-
}
|
|
131
|
-
return buf;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
export const removeColumns = function(dataArray:any[][], columnIndexes:number[]) {
|
|
135
|
-
const uniqueIndexes = [...new Set(columnIndexes)].sort().reverse();
|
|
136
|
-
uniqueIndexes.forEach(function(columnIndex) {
|
|
137
|
-
dataArray.forEach(function(row) {
|
|
138
|
-
row.splice(columnIndex, 1);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
export const hasContent = function(value:any) : boolean {
|
|
144
|
-
return value !== undefined && value !== null && value !== "";
|
|
1
|
+
|
|
2
|
+
export const b64toBlob = function (b64Data:string, contentType:string, sliceSize?:number): Blob {
|
|
3
|
+
// function taken from http://stackoverflow.com/a/16245768/2591950
|
|
4
|
+
// author Jeremy Banks http://stackoverflow.com/users/1114/jeremy-banks
|
|
5
|
+
contentType = contentType || '';
|
|
6
|
+
sliceSize = sliceSize || 512;
|
|
7
|
+
|
|
8
|
+
const byteCharacters = atob(b64Data);
|
|
9
|
+
const byteArrays = [];
|
|
10
|
+
|
|
11
|
+
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
|
|
12
|
+
const slice = byteCharacters.slice(offset, offset + sliceSize);
|
|
13
|
+
|
|
14
|
+
const byteNumbers = new Array(slice.length);
|
|
15
|
+
for (let i = 0; i < slice.length; i = i + 1) {
|
|
16
|
+
byteNumbers[i] = slice.charCodeAt(i);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const byteArray = new Uint8Array(byteNumbers);
|
|
20
|
+
|
|
21
|
+
byteArrays.push(byteArray);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return new Blob(byteArrays, {
|
|
25
|
+
type: contentType
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const templates = {excel: '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta name=ProgId content=Excel.Sheet> <meta name=Generator content="Microsoft Excel 11"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Convert a string to Base64.
|
|
33
|
+
*/
|
|
34
|
+
export const base64 = function(s:string) : string {
|
|
35
|
+
return btoa(unescape(encodeURIComponent(s)));
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const format = function(s:string, context:any) : string {
|
|
39
|
+
return s.replace(new RegExp("{(\\w+)}", "g"), function(m, p) {
|
|
40
|
+
return context[p] || "{" + p + "}";
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get element by ID.
|
|
46
|
+
* @param {*} element
|
|
47
|
+
*/
|
|
48
|
+
export const getTable = function(element :(HTMLTableElement|string)) : HTMLTableElement {
|
|
49
|
+
if (typeof element === 'string') {
|
|
50
|
+
return document.getElementById(element) as HTMLTableElement;
|
|
51
|
+
}
|
|
52
|
+
return element;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get element by ID.
|
|
57
|
+
* @param {*} element
|
|
58
|
+
*/
|
|
59
|
+
export const getAnchor = function(element :(HTMLAnchorElement|string)) : HTMLAnchorElement {
|
|
60
|
+
if (typeof element === 'string') {
|
|
61
|
+
return document.getElementById(element) as HTMLAnchorElement;
|
|
62
|
+
}
|
|
63
|
+
return element;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Encode a value for CSV.
|
|
68
|
+
* @param {*} value
|
|
69
|
+
*/
|
|
70
|
+
export const fixCSVField = function(value:string, csvDelimiter:string) : string {
|
|
71
|
+
let fixedValue = value;
|
|
72
|
+
const addQuotes = (value.indexOf(csvDelimiter) !== -1) || (value.indexOf('\r') !== -1) || (value.indexOf('\n') !== -1);
|
|
73
|
+
const replaceDoubleQuotes = (value.indexOf('"') !== -1);
|
|
74
|
+
|
|
75
|
+
if (replaceDoubleQuotes) {
|
|
76
|
+
fixedValue = fixedValue.replace(/"/g, '""');
|
|
77
|
+
}
|
|
78
|
+
if (addQuotes || replaceDoubleQuotes) {
|
|
79
|
+
fixedValue = '"' + fixedValue + '"';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return fixedValue;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const tableToArray = function(table:HTMLTableElement) : any[][] {
|
|
86
|
+
let tableInfo = Array.prototype.map.call(table.querySelectorAll('tr'), function(tr) {
|
|
87
|
+
return Array.prototype.map.call(tr.querySelectorAll('th,td'), function(td) {
|
|
88
|
+
return td.innerHTML;
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
return tableInfo;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const tableToCSV = function(table:HTMLTableElement, csvDelimiter:string = ',', csvNewLine:string = '\n') : string {
|
|
95
|
+
let data = "";
|
|
96
|
+
for (let i = 0; i < table.rows.length; i=i+1) {
|
|
97
|
+
const row = table.rows[i];
|
|
98
|
+
for (let j = 0; j < row.cells.length; j=j+1) {
|
|
99
|
+
const col = row.cells[j];
|
|
100
|
+
data = data + (j ? csvDelimiter : '') + fixCSVField(col.textContent.trim(), csvDelimiter);
|
|
101
|
+
}
|
|
102
|
+
data = data + csvNewLine;
|
|
103
|
+
}
|
|
104
|
+
return data;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const createDownloadLink = function(anchor:HTMLAnchorElement, base64data:string, exporttype:string, filename:string) : boolean {
|
|
108
|
+
if (window.navigator.msSaveBlob) {
|
|
109
|
+
const blob = b64toBlob(base64data, exporttype);
|
|
110
|
+
window.navigator.msSaveBlob(blob, filename);
|
|
111
|
+
return false;
|
|
112
|
+
} else if (window.URL.createObjectURL) {
|
|
113
|
+
const blob = b64toBlob(base64data, exporttype);
|
|
114
|
+
anchor.href = window.URL.createObjectURL(blob);
|
|
115
|
+
} else {
|
|
116
|
+
anchor.download = filename;
|
|
117
|
+
anchor.href = "data:" + exporttype + ";base64," + base64data;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Return true to allow the link to work
|
|
121
|
+
return true;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// String to ArrayBuffer
|
|
125
|
+
export const string2ArrayBuffer = function (s:string): ArrayBuffer {
|
|
126
|
+
let buf = new ArrayBuffer(s.length);
|
|
127
|
+
let view = new Uint8Array(buf);
|
|
128
|
+
for (let i=0; i !== s.length; ++i) {
|
|
129
|
+
view[i] = s.charCodeAt(i) & 0xFF;
|
|
130
|
+
}
|
|
131
|
+
return buf;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export const removeColumns = function(dataArray:any[][], columnIndexes:number[]) {
|
|
135
|
+
const uniqueIndexes = [...new Set(columnIndexes)].sort().reverse();
|
|
136
|
+
uniqueIndexes.forEach(function(columnIndex) {
|
|
137
|
+
dataArray.forEach(function(row) {
|
|
138
|
+
row.splice(columnIndex, 1);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export const hasContent = function(value:any) : boolean {
|
|
144
|
+
return value !== undefined && value !== null && value !== "";
|
|
145
145
|
}
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
import 'expect-puppeteer';
|
|
3
|
-
|
|
4
|
-
import ExcellentExport, { ConvertOptions, SheetOptions } from '../src/excellentexport';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
describe('convert() API', function() {
|
|
8
|
-
describe('test sheet options', 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('filterRowFn', 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
|
-
filterRowFn: (row) => {
|
|
36
|
-
if (row[0] === 'first') {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
] as SheetOptions[];
|
|
42
|
-
|
|
43
|
-
const workbook = ExcellentExport.convert(options, sheets);
|
|
44
|
-
expect(workbook).not.toBeNull();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('removeColumns', function() {
|
|
48
|
-
const options = {
|
|
49
|
-
anchor: '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: 'sometable'
|
|
59
|
-
},
|
|
60
|
-
removeColumns: [1]
|
|
61
|
-
}
|
|
62
|
-
] as SheetOptions[];
|
|
63
|
-
|
|
64
|
-
const workbook = ExcellentExport.convert(options, sheets);
|
|
65
|
-
expect(workbook).not.toBeNull();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
1
|
+
|
|
2
|
+
import 'expect-puppeteer';
|
|
3
|
+
|
|
4
|
+
import ExcellentExport, { ConvertOptions, SheetOptions } from '../src/excellentexport';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
describe('convert() API', function() {
|
|
8
|
+
describe('test sheet options', 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('filterRowFn', 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
|
+
filterRowFn: (row) => {
|
|
36
|
+
if (row[0] === 'first') {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
] as SheetOptions[];
|
|
42
|
+
|
|
43
|
+
const workbook = ExcellentExport.convert(options, sheets);
|
|
44
|
+
expect(workbook).not.toBeNull();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('removeColumns', function() {
|
|
48
|
+
const options = {
|
|
49
|
+
anchor: '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: 'sometable'
|
|
59
|
+
},
|
|
60
|
+
removeColumns: [1]
|
|
61
|
+
}
|
|
62
|
+
] as SheetOptions[];
|
|
63
|
+
|
|
64
|
+
const workbook = ExcellentExport.convert(options, sheets);
|
|
65
|
+
expect(workbook).not.toBeNull();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
@@ -1,71 +1,71 @@
|
|
|
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 '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
|
+
|