excellentexport 3.8.0 → 3.9.0
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/workflows/webpack.yml +6 -3
- package/README.md +57 -6
- package/dist/excellentexport.d.ts +8 -0
- package/dist/excellentexport.js +1 -1
- package/dist/excellentexport.js.LICENSE.txt +2 -2
- package/dist/format.d.ts +29 -0
- package/dist/utils.d.ts +1 -0
- package/index.bigtable.html +19 -44
- package/index.format.html +100 -0
- package/package.json +24 -24
- package/src/excellentexport.ts +43 -4
- package/src/format.ts +52 -0
- package/src/utils.ts +145 -141
- package/test/convert.format.ts +56 -0
- package/tsconfig.json +17 -17
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*!
|
|
1
|
+
/*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
|
|
2
2
|
|
|
3
|
-
/*!
|
|
3
|
+
/*! xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare enum CellType {
|
|
2
|
+
TEXT = "s",
|
|
3
|
+
NUMBER = "n",
|
|
4
|
+
DATE = "d",
|
|
5
|
+
BOOLEAN = "b"
|
|
6
|
+
}
|
|
7
|
+
export declare enum CellPattern {
|
|
8
|
+
INTEGER = "0",
|
|
9
|
+
DECIMAL = "0.00",
|
|
10
|
+
DATE = "dd/mm/yyyy",
|
|
11
|
+
TIME = "hh:mm:ss",
|
|
12
|
+
DATETIME = "dd/mm/yyyy hh:mm:ss",
|
|
13
|
+
CURRENCY = "[$$-409]#,##0.00;[RED]-[$$-409]#,##0.00",
|
|
14
|
+
PERCENTAGE = "0.00%",
|
|
15
|
+
EXPONENT = "0.00E+00",
|
|
16
|
+
TEXT = "@"
|
|
17
|
+
}
|
|
18
|
+
export interface CellFormat {
|
|
19
|
+
type: CellType;
|
|
20
|
+
pattern?: CellPattern;
|
|
21
|
+
}
|
|
22
|
+
export interface CellFormats {
|
|
23
|
+
[key: string]: CellFormat;
|
|
24
|
+
}
|
|
25
|
+
export declare const PredefinedFormat: CellFormats;
|
|
26
|
+
export interface FormatDefinition {
|
|
27
|
+
range: string;
|
|
28
|
+
format?: CellFormat;
|
|
29
|
+
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -27,3 +27,4 @@ export declare const tableToCSV: (table: HTMLTableElement, csvDelimiter?: string
|
|
|
27
27
|
export declare const createDownloadLink: (anchor: HTMLAnchorElement, base64data: string, exporttype: string, filename: string) => boolean;
|
|
28
28
|
export declare const string2ArrayBuffer: (s: string) => ArrayBuffer;
|
|
29
29
|
export declare const removeColumns: (dataArray: any[][], columnIndexes: number[]) => void;
|
|
30
|
+
export declare const hasContent: (value: any) => boolean;
|
package/index.bigtable.html
CHANGED
|
@@ -2,63 +2,38 @@
|
|
|
2
2
|
<head>
|
|
3
3
|
<meta charset="utf-8">
|
|
4
4
|
<title>Export to excel test</title>
|
|
5
|
-
<script src="excellentexport.js"></script>
|
|
5
|
+
<script src="dist/excellentexport.js"></script>
|
|
6
6
|
<style>
|
|
7
7
|
table, tr, td {
|
|
8
8
|
border: 1px black solid;
|
|
9
9
|
}
|
|
10
10
|
</style>
|
|
11
|
+
<script>
|
|
12
|
+
function action(format) {
|
|
13
|
+
return ExcellentExport.convert({
|
|
14
|
+
anchor: 'bigdata-' + format,
|
|
15
|
+
filename: 'big_table.' + format,
|
|
16
|
+
format: format
|
|
17
|
+
}, [{
|
|
18
|
+
name: 'Big Table',
|
|
19
|
+
from: {
|
|
20
|
+
table: 'bigtable'
|
|
21
|
+
}
|
|
22
|
+
}]);
|
|
23
|
+
}
|
|
24
|
+
</script>
|
|
11
25
|
</head>
|
|
12
26
|
<body>
|
|
13
27
|
<h1>ExcellentExport.js</h1>
|
|
14
28
|
|
|
15
29
|
Check on <a href="http://jordiburgos.com">jordiburgos.com</a> and <a href="https://github.com/jmaister/excellentexport">GitHub</a>.
|
|
16
30
|
|
|
17
|
-
<h3>Test page</h3>
|
|
18
|
-
|
|
19
|
-
<br/>
|
|
20
|
-
|
|
21
|
-
<a download="somedata.xls" href="#" onclick="return ExcellentExport.excel(this, 'datatable', 'Sheet Name Here');">Export to Excel</a>
|
|
22
|
-
<br/>
|
|
23
|
-
|
|
24
|
-
<a download="somedata.csv" href="#" onclick="return ExcellentExport.csv(this, 'datatable');">Export to CSV - UTF8</a>
|
|
25
|
-
<br/>
|
|
26
|
-
<a download="somedata.csv" href="#" onclick="return ExcellentExport.csv(this, 'datatable', ';');">Export to CSV - Using semicolon ";" separator - UTF8</a>
|
|
27
|
-
<br/>
|
|
31
|
+
<h3>Big Table Test page</h3>
|
|
28
32
|
|
|
29
|
-
<table id="datatable">
|
|
30
|
-
<tr>
|
|
31
|
-
<th>Column 1</th>
|
|
32
|
-
<th>Column "cool" 2</th>
|
|
33
|
-
<th>Column 3</th>
|
|
34
|
-
<th>Column 4</th>
|
|
35
|
-
</tr>
|
|
36
|
-
<tr>
|
|
37
|
-
<td>100,111</td>
|
|
38
|
-
<td>200</td>
|
|
39
|
-
<td>300</td>
|
|
40
|
-
<td>áéíóú</td>
|
|
41
|
-
</tr>
|
|
42
|
-
<tr>
|
|
43
|
-
<td>400</td>
|
|
44
|
-
<td>500</td>
|
|
45
|
-
<td>Chinese chars: 解决导出csv中文乱码问题</td>
|
|
46
|
-
<td>àèìòù</td>
|
|
47
|
-
</tr>
|
|
48
|
-
<tr>
|
|
49
|
-
<td>Text</td>
|
|
50
|
-
<td>More text</td>
|
|
51
|
-
<td>Text with
|
|
52
|
-
new line</td>
|
|
53
|
-
<td>ç ñ ÄËÏÖÜ äëïöü</td>
|
|
54
|
-
</tr>
|
|
55
|
-
</table>
|
|
56
33
|
|
|
57
|
-
|
|
58
|
-
<br/>
|
|
59
|
-
<
|
|
60
|
-
<a download="bigdata.xls" href="#" onclick="return ExcellentExport.excel(this, 'bigtable', 'Big Data Sheet');">Export to Excel very big table</a><br/>
|
|
61
|
-
<a download="bigdata.csv" href="#" onclick="return ExcellentExport.csv(this, 'bigtable');">Export to CSV very big table</a>
|
|
34
|
+
<a id="bigdata-xlsx" download="bigdata.xlsx" href="#" onclick="return action('xlsx')">Export to XLSX very big table</a><br/>
|
|
35
|
+
<a id="bigdata-xls" download="bigdata.xls" href="#" onclick="return action('xls')">Export to XLS very big table</a><br/>
|
|
36
|
+
<a id="bigdata-csv" download="bigdata.csv" href="#" onclick="return action('csv')">Export to CSV very big table</a>
|
|
62
37
|
<table id="bigtable">
|
|
63
38
|
<br/>
|
|
64
39
|
</table>
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>Export to excel test</title>
|
|
6
|
+
<script src="dist/excellentexport.js"></script>
|
|
7
|
+
<style>
|
|
8
|
+
table, tr, td {
|
|
9
|
+
border: 1px black solid;
|
|
10
|
+
}
|
|
11
|
+
</style>
|
|
12
|
+
<script>
|
|
13
|
+
function newApi(format) {
|
|
14
|
+
return ExcellentExport.convert({
|
|
15
|
+
anchor: 'anchorNewApi-' + format,
|
|
16
|
+
filename: 'data',
|
|
17
|
+
format: format
|
|
18
|
+
}, [{
|
|
19
|
+
name: 'Formatted Sheet',
|
|
20
|
+
from: {
|
|
21
|
+
table: 'datatable'
|
|
22
|
+
},
|
|
23
|
+
formats: [
|
|
24
|
+
{ range: "A2:A10", format: ExcellentExport.formats.INTEGER },
|
|
25
|
+
{ range: "B2:B10", format: ExcellentExport.formats.TEXT },
|
|
26
|
+
{ range: "C2:C10", format: ExcellentExport.formats.DATE },
|
|
27
|
+
{ range: "D2:D10", format: ExcellentExport.formats.DECIMAL },
|
|
28
|
+
{ range: "E2:E10", format: ExcellentExport.formats.BOOLEAN },
|
|
29
|
+
{ range: "F2:F10", format: ExcellentExport.formats.INTEGER },
|
|
30
|
+
{ range: "A5:E5", format: ExcellentExport.formats.TEXT },
|
|
31
|
+
{ range: "A6", format: ExcellentExport.formats.DECIMAL },
|
|
32
|
+
],
|
|
33
|
+
}]);
|
|
34
|
+
}
|
|
35
|
+
</script>
|
|
36
|
+
</head>
|
|
37
|
+
<body>
|
|
38
|
+
<h1>ExcellentExport.js</h1>
|
|
39
|
+
|
|
40
|
+
<h3>Test page</h3>
|
|
41
|
+
|
|
42
|
+
Test table:
|
|
43
|
+
<table id="datatable">
|
|
44
|
+
<tr>
|
|
45
|
+
<th>ID</th>
|
|
46
|
+
<th>Name</th>
|
|
47
|
+
<th>Birthdate</th>
|
|
48
|
+
<th>Salary</th>
|
|
49
|
+
<th>Active</th>
|
|
50
|
+
<th>Big number</th>
|
|
51
|
+
</tr>
|
|
52
|
+
<tr>
|
|
53
|
+
<td>1</td>
|
|
54
|
+
<td>John</td>
|
|
55
|
+
<td>1980-12-10</td>
|
|
56
|
+
<td>98762000.55</td>
|
|
57
|
+
<td>1</td>
|
|
58
|
+
<td>987654321987654</td>
|
|
59
|
+
</tr>
|
|
60
|
+
<tr>
|
|
61
|
+
<td>2</td>
|
|
62
|
+
<td>Peter</td>
|
|
63
|
+
<td>1978-01-23</td>
|
|
64
|
+
<td>98762500.43</td>
|
|
65
|
+
<td>0</td>
|
|
66
|
+
<td>876543219987654</td>
|
|
67
|
+
</tr>
|
|
68
|
+
<tr>
|
|
69
|
+
<td>3</td>
|
|
70
|
+
<td>George</td>
|
|
71
|
+
<td>1985-11-30</td>
|
|
72
|
+
<td>98761800.98</td>
|
|
73
|
+
<td>1</td>
|
|
74
|
+
<td>765432198987654</td>
|
|
75
|
+
</tr>
|
|
76
|
+
<tr>
|
|
77
|
+
<td>End</td>
|
|
78
|
+
<td>End</td>
|
|
79
|
+
<td>End</td>
|
|
80
|
+
<td>End</td>
|
|
81
|
+
<td>End</td>
|
|
82
|
+
<td>End</td>
|
|
83
|
+
</tr>
|
|
84
|
+
<tr>
|
|
85
|
+
<td>9876543.21</td>
|
|
86
|
+
<td></td>
|
|
87
|
+
<td></td>
|
|
88
|
+
<td></td>
|
|
89
|
+
<td></td>
|
|
90
|
+
<td></td>
|
|
91
|
+
</tr>
|
|
92
|
+
</table>
|
|
93
|
+
|
|
94
|
+
<br/>
|
|
95
|
+
|
|
96
|
+
<a href="#" id="anchorNewApi-xlsx" onclick="return newApi('xlsx');">Export Excel</a>
|
|
97
|
+
<a href="#" id="anchorNewApi-csv" onclick="return newApi('csv');">Export CSV</a>
|
|
98
|
+
|
|
99
|
+
</body>
|
|
100
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "excellentexport",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"description": "Client side JavaScript export to Excel or CSV",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "http://jordiburgos.com",
|
|
@@ -27,32 +27,32 @@
|
|
|
27
27
|
},
|
|
28
28
|
"main": "dist/excellentexport.js",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@babel/core": "7.
|
|
31
|
-
"@babel/plugin-proposal-class-properties": "7.
|
|
32
|
-
"@babel/plugin-transform-flow-strip-types": "7.
|
|
33
|
-
"@babel/preset-env": "7.
|
|
34
|
-
"@types/jest": "
|
|
35
|
-
"@types/jest-environment-puppeteer": "5.0.
|
|
36
|
-
"@types/node": "
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"blob-polyfill": "6.0.20211015",
|
|
30
|
+
"@babel/core": "7.20.12",
|
|
31
|
+
"@babel/plugin-proposal-class-properties": "7.18.6",
|
|
32
|
+
"@babel/plugin-transform-flow-strip-types": "7.19.0",
|
|
33
|
+
"@babel/preset-env": "7.20.2",
|
|
34
|
+
"@types/jest": "29.4.0",
|
|
35
|
+
"@types/jest-environment-puppeteer": "5.0.3",
|
|
36
|
+
"@types/node": "18.13.0",
|
|
37
|
+
"babel-loader": "9.1.2",
|
|
38
|
+
"blob-polyfill": "7.0.20220408",
|
|
40
39
|
"coveralls": "3.1.1",
|
|
41
40
|
"cross-env": "7.0.3",
|
|
42
|
-
"html-loader": "
|
|
43
|
-
"jest": "
|
|
44
|
-
"jest-
|
|
45
|
-
"puppeteer": "
|
|
46
|
-
"
|
|
47
|
-
"ts-
|
|
48
|
-
"ts-
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"webpack
|
|
53
|
-
"webpack-
|
|
41
|
+
"html-loader": "4.2.0",
|
|
42
|
+
"jest": "29.4.2",
|
|
43
|
+
"jest-environment-jsdom": "^29.4.2",
|
|
44
|
+
"jest-puppeteer": "7.0.0",
|
|
45
|
+
"puppeteer": "19.6.3",
|
|
46
|
+
"ts-jest": "29.0.5",
|
|
47
|
+
"ts-loader": "9.4.2",
|
|
48
|
+
"ts-node": "10.9.1",
|
|
49
|
+
"typescript": "4.9.5",
|
|
50
|
+
"webdriverio": "8.3.5",
|
|
51
|
+
"webpack": "5.75.0",
|
|
52
|
+
"webpack-cli": "5.0.1",
|
|
53
|
+
"webpack-dev-server": "4.11.1",
|
|
54
54
|
"webpack-node-externals": "3.0.0",
|
|
55
|
-
"xlsx": "0.
|
|
55
|
+
"xlsx": "0.18.5"
|
|
56
56
|
},
|
|
57
57
|
"resolutions": {
|
|
58
58
|
"json-schema": "0.4.0"
|
package/src/excellentexport.ts
CHANGED
|
@@ -8,9 +8,17 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import * as XLSX from 'xlsx';
|
|
11
|
+
import { CellType, FormatDefinition, PredefinedFormat } from './format';
|
|
11
12
|
|
|
12
13
|
import * as utils from './utils';
|
|
13
14
|
|
|
15
|
+
// Fix for IE11: https://stackoverflow.com/questions/69485778/new-typescript-version-does-not-include-window-navigator-mssaveblob
|
|
16
|
+
declare global {
|
|
17
|
+
interface Navigator {
|
|
18
|
+
msSaveBlob?: (blob: any, defaultName?: string) => boolean
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
export interface ConvertOptions {
|
|
15
23
|
anchor?: (string|HTMLAnchorElement),
|
|
16
24
|
openAsDownload?: boolean,
|
|
@@ -22,6 +30,7 @@ export interface FromOptions {
|
|
|
22
30
|
table?: (string|HTMLTableElement),
|
|
23
31
|
array?: any[][],
|
|
24
32
|
}
|
|
33
|
+
|
|
25
34
|
export interface SheetOptions {
|
|
26
35
|
name: string,
|
|
27
36
|
from: FromOptions,
|
|
@@ -29,13 +38,13 @@ export interface SheetOptions {
|
|
|
29
38
|
filterRowFn?(row:any[]): boolean ,
|
|
30
39
|
fixValue?(value:any, row:number, column:number): any,
|
|
31
40
|
fixArray?(array:any[][]): any[][],
|
|
32
|
-
rtl?: boolean
|
|
41
|
+
rtl?: boolean,
|
|
42
|
+
formats?: (FormatDefinition | null)[],
|
|
33
43
|
}
|
|
34
44
|
|
|
35
|
-
|
|
36
45
|
const ExcellentExport = function() {
|
|
37
46
|
|
|
38
|
-
const version = "3.
|
|
47
|
+
const version = "3.9.0";
|
|
39
48
|
|
|
40
49
|
/*
|
|
41
50
|
ExcellentExport.convert(options, sheets);
|
|
@@ -131,11 +140,40 @@ const ExcellentExport = function() {
|
|
|
131
140
|
// Create sheet
|
|
132
141
|
workbook.SheetNames.push(name);
|
|
133
142
|
const worksheet = XLSX.utils.aoa_to_sheet(dataArray, {sheet: name} as XLSX.AOA2SheetOpts);
|
|
143
|
+
|
|
144
|
+
// Apply format
|
|
145
|
+
if (sheetConf.formats) {
|
|
146
|
+
sheetConf.formats.forEach(f => {
|
|
147
|
+
const range = XLSX.utils.decode_range(f.range);
|
|
148
|
+
for (let R = range.s.r; R <= range.e.r; ++R) {
|
|
149
|
+
for (let C = range.s.c; C <= range.e.c; ++C) {
|
|
150
|
+
const cell = worksheet[XLSX.utils.encode_cell({r: R, c: C})];
|
|
151
|
+
if (cell && utils.hasContent(cell.v)) {
|
|
152
|
+
// type
|
|
153
|
+
cell.t = f.format.type;
|
|
154
|
+
|
|
155
|
+
// type fix
|
|
156
|
+
if (f.format?.type == CellType.BOOLEAN) {
|
|
157
|
+
const v = cell.v.toString().toLowerCase();
|
|
158
|
+
if (v == 'true' || v == '1') cell.v = true;
|
|
159
|
+
if (v == 'false' || v == '0') cell.v = false;
|
|
160
|
+
}
|
|
161
|
+
// pattern
|
|
162
|
+
if (f.format?.pattern) {
|
|
163
|
+
cell.z = f.format.pattern;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
134
172
|
workbook.Sheets[name] = worksheet;
|
|
135
173
|
workbook.Views.push({RTL: options.rtl || sheetConf.rtl || false});
|
|
136
174
|
});
|
|
137
175
|
|
|
138
|
-
const wbOut:string = XLSX.write(workbook, {bookType: options.format, bookSST:true, type: 'binary'});
|
|
176
|
+
const wbOut:string = XLSX.write(workbook, {bookType: options.format, bookSST:true, type: 'binary', compression: true});
|
|
139
177
|
try {
|
|
140
178
|
const blob = new Blob([utils.string2ArrayBuffer(wbOut)], { type: "application/octet-stream" });
|
|
141
179
|
const filename = (options.filename || 'download') + '.' + options.format;
|
|
@@ -170,6 +208,7 @@ const ExcellentExport = function() {
|
|
|
170
208
|
version: function(): string {
|
|
171
209
|
return version;
|
|
172
210
|
},
|
|
211
|
+
formats: PredefinedFormat,
|
|
173
212
|
excel: function(anchor:(HTMLAnchorElement|string), table:HTMLTableElement, name:string) {
|
|
174
213
|
table = utils.getTable(table);
|
|
175
214
|
anchor = utils.getAnchor(anchor);
|
package/src/format.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
export enum CellType {
|
|
3
|
+
TEXT = 's',
|
|
4
|
+
NUMBER = 'n',
|
|
5
|
+
DATE = 'd',
|
|
6
|
+
BOOLEAN = 'b',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export enum CellPattern {
|
|
10
|
+
INTEGER = '0',
|
|
11
|
+
DECIMAL = '0.00',
|
|
12
|
+
DATE = 'dd/mm/yyyy',
|
|
13
|
+
TIME = 'hh:mm:ss',
|
|
14
|
+
DATETIME = 'dd/mm/yyyy hh:mm:ss',
|
|
15
|
+
CURRENCY = '[$$-409]#,##0.00;[RED]-[$$-409]#,##0.00',
|
|
16
|
+
PERCENTAGE = '0.00%',
|
|
17
|
+
EXPONENT = '0.00E+00',
|
|
18
|
+
TEXT = '@',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface CellFormat {
|
|
22
|
+
type: CellType,
|
|
23
|
+
pattern?: CellPattern,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Define structure for predefined formats
|
|
27
|
+
export interface CellFormats {
|
|
28
|
+
[key: string]: CellFormat
|
|
29
|
+
}
|
|
30
|
+
export const PredefinedFormat : CellFormats = {
|
|
31
|
+
NUMBER: { type: CellType.NUMBER},
|
|
32
|
+
INTEGER: { type: CellType.NUMBER, pattern: CellPattern.INTEGER },
|
|
33
|
+
DECIMAL: { type: CellType.NUMBER, pattern: CellPattern.DECIMAL },
|
|
34
|
+
CURRENCY: { type: CellType.NUMBER, pattern: CellPattern.CURRENCY },
|
|
35
|
+
PERCENTAGE: { type: CellType.NUMBER, pattern: CellPattern.PERCENTAGE },
|
|
36
|
+
EXPONENT: { type: CellType.NUMBER, pattern: CellPattern.EXPONENT },
|
|
37
|
+
|
|
38
|
+
DATE: { type: CellType.DATE, pattern: CellPattern.DATE },
|
|
39
|
+
|
|
40
|
+
TIME: { type: CellType.DATE, pattern: CellPattern.TIME },
|
|
41
|
+
DATETIME: { type: CellType.DATE, pattern: CellPattern.DATETIME },
|
|
42
|
+
|
|
43
|
+
TEXT: { type: CellType.TEXT, pattern: CellPattern.TEXT },
|
|
44
|
+
|
|
45
|
+
BOOLEAN: { type: CellType.BOOLEAN },
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface FormatDefinition {
|
|
49
|
+
range: string,
|
|
50
|
+
format?: CellFormat,
|
|
51
|
+
}
|
|
52
|
+
|