@loaders.gl/excel 3.1.0-alpha.5 → 3.1.0-beta.4
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/dist/bundle.d.ts +1 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +34714 -0
- package/dist/es5/excel-loader.js +1 -1
- package/dist/es5/excel-loader.js.map +1 -1
- package/dist/esm/excel-loader.js +1 -1
- package/dist/esm/excel-loader.js.map +1 -1
- package/dist/excel-loader.d.ts +1 -0
- package/dist/excel-loader.d.ts.map +1 -0
- package/dist/excel-loader.js +31 -0
- package/dist/excel-worker.js +34827 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/lib/encode-excel.d.ts +1 -0
- package/dist/lib/encode-excel.d.ts.map +1 -0
- package/dist/lib/encode-excel.js +81 -0
- package/dist/lib/parse-excel.d.ts +1 -0
- package/dist/lib/parse-excel.d.ts.map +1 -0
- package/dist/lib/parse-excel.js +47 -0
- package/dist/workers/excel-worker.d.ts +1 -0
- package/dist/workers/excel-worker.d.ts.map +1 -0
- package/dist/workers/excel-worker.js +5 -0
- package/package.json +6 -7
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/excel-worker.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAC,WAAW,IAAI,iBAAiB,EAAE,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAKpF,YAAY,EAAC,kBAAkB,EAAC,CAAC;AACjC,OAAO,EAAC,iBAAiB,EAAC,CAAC;AAE3B;;GAEG;AACH,eAAO,MAAM,WAAW;yBAED,WAAW;;;;;;;;;;;CAEjC,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,gBAA8B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._typecheckLoader = exports.ExcelLoader = exports.ExcelWorkerLoader = void 0;
|
|
4
|
+
const excel_loader_1 = require("./excel-loader");
|
|
5
|
+
Object.defineProperty(exports, "ExcelWorkerLoader", { enumerable: true, get: function () { return excel_loader_1.ExcelLoader; } });
|
|
6
|
+
const parse_excel_1 = require("./lib/parse-excel");
|
|
7
|
+
/**
|
|
8
|
+
* Loader for Excel files
|
|
9
|
+
*/
|
|
10
|
+
exports.ExcelLoader = {
|
|
11
|
+
...excel_loader_1.ExcelLoader,
|
|
12
|
+
parse: (arrayBuffer, options) => (0, parse_excel_1.parseExcel)(arrayBuffer, options)
|
|
13
|
+
};
|
|
14
|
+
exports._typecheckLoader = exports.ExcelLoader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-excel.d.ts","sourceRoot":"","sources":["../../src/lib/encode-excel.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8EE"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import * as xlsx from 'xlsx';
|
|
3
|
+
/**
|
|
4
|
+
* Saves JSON data in Excel format for html, ods, xml, xlsb and xlsx file types.
|
|
5
|
+
* @param filePath Local data file path.
|
|
6
|
+
* @param fileData Raw data to save.
|
|
7
|
+
* @param tableName Table name for data files with multiple tables support.
|
|
8
|
+
* @param showData Show saved data callback.
|
|
9
|
+
*
|
|
10
|
+
public saveData(filePath: string, fileData: any, tableName: string, showData?: Function): void {
|
|
11
|
+
const fileType: string = filePath.substr(filePath.lastIndexOf('.'));
|
|
12
|
+
fileData = this.jsonToExcelData(fileData, fileType, tableName);
|
|
13
|
+
if ( fileData.length > 0) {
|
|
14
|
+
// TODO: change this to async later
|
|
15
|
+
fs.writeFile(filePath, fileData, (error) => showData(error));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Converts JSON data to Excel data formats.
|
|
21
|
+
* @param jsonData Json data to convert.
|
|
22
|
+
* @param bookType Excel data file/book type.
|
|
23
|
+
*
|
|
24
|
+
private jsonToExcelData(jsonData: any, fileType: string, tableName: string): any {
|
|
25
|
+
console.debug('jsonToExcelData(): creating excel data:', fileType);
|
|
26
|
+
|
|
27
|
+
// create new workbook
|
|
28
|
+
const workbook = xlsx.utils.book_new();
|
|
29
|
+
|
|
30
|
+
// convert json data to worksheet format
|
|
31
|
+
const worksheet = xlsx.utils.json_to_sheet(jsonData, {
|
|
32
|
+
//header: JSON.parse(this._viewConfig.columns)
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// append worksheet to workbook
|
|
36
|
+
xlsx.utils.book_append_sheet(workbook, worksheet, tableName);
|
|
37
|
+
|
|
38
|
+
// get text data string or binary spreadsheet data buffer
|
|
39
|
+
let data: any = '';
|
|
40
|
+
if (fileType === 'html' || fileType === 'xml') {
|
|
41
|
+
data = xlsx.write(workbook, {
|
|
42
|
+
type: 'string',
|
|
43
|
+
compression: false,
|
|
44
|
+
bookType: getBookType(fileType)
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
data = xlsx.write(workbook, {
|
|
48
|
+
type: 'buffer',
|
|
49
|
+
compression: true, // use zip compression for zip-based formats
|
|
50
|
+
bookType: getBookType(fileType)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return data;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Converts file type to Excel book type.
|
|
61
|
+
* @param {string} fileType File type: .html, .ods, .xml, .xlsb, .xlsx, etc.
|
|
62
|
+
* @returns {xlsx.BookType}
|
|
63
|
+
*
|
|
64
|
+
function getBookType(fileType) {
|
|
65
|
+
// TODO: must be a better way to do this string to type conversion :)
|
|
66
|
+
switch (fileType) {
|
|
67
|
+
case '.html':
|
|
68
|
+
return 'html';
|
|
69
|
+
case '.ods':
|
|
70
|
+
return 'ods';
|
|
71
|
+
case '.xml':
|
|
72
|
+
return 'xlml';
|
|
73
|
+
case '.xlsb':
|
|
74
|
+
return 'xlsb';
|
|
75
|
+
case '.xlsx':
|
|
76
|
+
return 'xlsx';
|
|
77
|
+
default:
|
|
78
|
+
return 'xlsb';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-excel.d.ts","sourceRoot":"","sources":["../../src/lib/parse-excel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAOxD;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,kBAAkB,oBAuCtF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseExcel = void 0;
|
|
4
|
+
const xlsx_1 = require("xlsx");
|
|
5
|
+
// import {convertToArrayRow} from '@loaders.gl/schema';
|
|
6
|
+
// local table names cache with dataUrl/tableNames array key/values
|
|
7
|
+
const dataTableNamesMap = {};
|
|
8
|
+
/**
|
|
9
|
+
* Gets local or remote Excel file data.
|
|
10
|
+
* @param arrayBuffer Loaded data
|
|
11
|
+
* @param options Data parse options.
|
|
12
|
+
*/
|
|
13
|
+
async function parseExcel(arrayBuffer, options) {
|
|
14
|
+
const dataUrl = 'dummy';
|
|
15
|
+
// const dataFileType: string = dataUrl.substr(dataUrl.lastIndexOf('.')); // file extension
|
|
16
|
+
// create Excel 'workbook'
|
|
17
|
+
const workbook = (0, xlsx_1.read)(arrayBuffer, {
|
|
18
|
+
type: 'array'
|
|
19
|
+
// cellDates: true
|
|
20
|
+
});
|
|
21
|
+
// load data sheets
|
|
22
|
+
let dataRows = [];
|
|
23
|
+
dataTableNamesMap[dataUrl] = [];
|
|
24
|
+
if (workbook.SheetNames.length > 0) {
|
|
25
|
+
if (workbook.SheetNames.length > 1) {
|
|
26
|
+
// cache sheet names
|
|
27
|
+
dataTableNamesMap[dataUrl] = workbook.SheetNames;
|
|
28
|
+
// eslint-ignore-next-line
|
|
29
|
+
// console.debug(`getData(): file: sheetNames:`, workbook.SheetNames);
|
|
30
|
+
}
|
|
31
|
+
// determine spreadsheet to load
|
|
32
|
+
let sheetName = workbook.SheetNames[0];
|
|
33
|
+
if (options?.excel?.sheet && workbook.SheetNames.indexOf(options?.excel?.sheet) >= 0) {
|
|
34
|
+
// reset to requested table name
|
|
35
|
+
sheetName = options?.excel?.sheet;
|
|
36
|
+
}
|
|
37
|
+
// get worksheet data row objects array
|
|
38
|
+
const worksheet = workbook.Sheets[sheetName];
|
|
39
|
+
dataRows = xlsx_1.utils.sheet_to_json(worksheet);
|
|
40
|
+
// const headers = dataRows.length ? Object.keys(dataRows[0]) : [];
|
|
41
|
+
// if (options?.excel?.type === 'array-row-table') {
|
|
42
|
+
// dataRows = dataRows.map(row => convertToArrayRow(row, headers))
|
|
43
|
+
// }
|
|
44
|
+
}
|
|
45
|
+
return dataRows;
|
|
46
|
+
}
|
|
47
|
+
exports.parseExcel = parseExcel;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excel-worker.d.ts","sourceRoot":"","sources":["../../src/workers/excel-worker.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/excel",
|
|
3
|
-
"version": "3.1.0-
|
|
3
|
+
"version": "3.1.0-beta.4",
|
|
4
4
|
"description": "Framework-independent loader for Excel files",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -31,14 +31,13 @@
|
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
33
|
"pre-build": "npm run build-bundle && npm run build-worker",
|
|
34
|
-
"
|
|
35
|
-
"build-
|
|
36
|
-
"build-worker": "webpack --entry ./src/workers/excel-worker.ts --output ./dist/excel-worker.js --config ../../scripts/webpack/worker.js"
|
|
34
|
+
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/bundle.js",
|
|
35
|
+
"build-worker": "esbuild src/workers/excel-worker.ts --bundle --outfile=dist/excel-worker.js"
|
|
37
36
|
},
|
|
38
37
|
"dependencies": {
|
|
39
|
-
"@loaders.gl/loader-utils": "3.1.0-
|
|
40
|
-
"@loaders.gl/schema": "3.1.0-
|
|
38
|
+
"@loaders.gl/loader-utils": "3.1.0-beta.4",
|
|
39
|
+
"@loaders.gl/schema": "3.1.0-beta.4",
|
|
41
40
|
"xlsx": "^0.17.0"
|
|
42
41
|
},
|
|
43
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "5c7c74215416b30fcea98f5cecc820c8a21023b3"
|
|
44
43
|
}
|