From 93be9c6360639b766e96e2d2ccff53661f9ebb0d Mon Sep 17 00:00:00 2001 From: wenjiarui Date: Mon, 16 Jan 2023 11:03:25 +0800 Subject: [PATCH 1/2] package --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a645dbf..94c254a 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "dependencies": { "lodash": "^4.17.21", "oak-domain": "file:../oak-domain", - "oak-external-sdk": "file:../oak-external-sdk" + "oak-external-sdk": "file:../oak-external-sdk", + "xlsx": "0.18.5" }, "devDependencies": { "@types/node": "^18.0.0", @@ -26,4 +27,4 @@ "tslib": "^2.4.0", "typescript": "~4.7.4" } -} +} \ No newline at end of file From 8533a93fe25ac6bd0406d879dd47c6c17248957c Mon Sep 17 00:00:00 2001 From: wenjiarui Date: Mon, 16 Jan 2023 19:36:39 +0800 Subject: [PATCH 2/2] HouseEntity --- lib/port.js | 13 +++++++++++-- package.json | 4 ++-- src/port.ts | 18 ++++++++++++++---- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/port.js b/lib/port.js index b2ea3c2..7a830b7 100644 --- a/lib/port.js +++ b/lib/port.js @@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.exportEntity = exports.importEntity = exports.clearPorts = exports.registerPorts = void 0; const tslib_1 = require("tslib"); const assert_1 = tslib_1.__importDefault(require("assert")); +const xlsx_1 = require("xlsx"); const Importations = {}; const Exportations = {}; function registerPorts(importations, exportations) { @@ -41,10 +42,18 @@ async function importEntity(params, context) { const entity = params.get('entity'); const file = params.get('file'); const id = params.get('id'); - throw new Error('not implement yet'); + const arrayBuffer = await file.arrayBuffer(); + const workbook = (0, xlsx_1.read)(arrayBuffer); + const { SheetNames, Sheets } = workbook; + for (const sheetName of SheetNames) { + const sheet = Sheets[sheetName]; + const dataList = xlsx_1.utils.sheet_to_json(sheet, {}); + console.log(dataList); + } + // throw new Error('not implement yet'); } exports.importEntity = importEntity; async function exportEntity(params, context) { - throw new Error('not implement yet'); + throw new Error('export not implement yet'); } exports.exportEntity = exportEntity; diff --git a/package.json b/package.json index 4ba17ab..6793b3d 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "lodash": "^4.17.21", "oak-domain": "file:../oak-domain", "oak-external-sdk": "file:../oak-external-sdk", - "xlsx": "0.18.5" + "xlsx": "^0.18.5" }, "devDependencies": { "@types/node": "^18.0.0", @@ -27,4 +27,4 @@ "tslib": "^2.4.0", "typescript": "~4.7.4" } -} \ No newline at end of file +} diff --git a/src/port.ts b/src/port.ts index f7e32ae..1fa83d3 100644 --- a/src/port.ts +++ b/src/port.ts @@ -1,7 +1,7 @@ import assert from 'assert'; import { Importation, Exportation, EntityDict, SelectOption } from 'oak-domain/lib/types/Entity'; import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore'; - +import { read, utils } from 'xlsx'; const Importations: Record = {}; const Exportations: Record = {}; @@ -47,8 +47,18 @@ export async function importEntity< const entity = params.get('entity') as keyof ED; const file = params.get('file') as File; const id = params.get('id') as string; - - throw new Error('not implement yet'); + const arrayBuffer = await file.arrayBuffer(); + const workbook = read(arrayBuffer); + const { SheetNames, Sheets } = workbook; + for (const sheetName of SheetNames) { + const sheet = Sheets[sheetName]; + const dataList = utils.sheet_to_json( + sheet + ); + console.log(dataList); + } + + // throw new Error('not implement yet'); } export async function exportEntity< @@ -60,5 +70,5 @@ export async function exportEntity< id: string; filter?: ED[T]['Selection']['filter']; }, context: Cxt): Promise { - throw new Error('not implement yet'); + throw new Error('export not implement yet'); }