From 6bcc83d92087894546bf6f083c0f780a6994519a Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Wed, 10 Nov 2021 17:23:21 +0100 Subject: [PATCH] excel import - ability to skip header --- packages/web/src/forms/FormArgument.svelte | 2 ++ plugins/dbgate-plugin-excel/src/backend/reader.js | 10 +++++++++- plugins/dbgate-plugin-excel/src/frontend/index.js | 8 ++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/web/src/forms/FormArgument.svelte b/packages/web/src/forms/FormArgument.svelte index 853509c6..1fa74f70 100644 --- a/packages/web/src/forms/FormArgument.svelte +++ b/packages/web/src/forms/FormArgument.svelte @@ -13,6 +13,8 @@ {#if arg.type == 'text'} +{:else if arg.type == 'number'} + {:else if arg.type == 'checkbox'} {:else if arg.type == 'select'} diff --git a/plugins/dbgate-plugin-excel/src/backend/reader.js b/plugins/dbgate-plugin-excel/src/backend/reader.js index 3535e40f..1eadc1eb 100644 --- a/plugins/dbgate-plugin-excel/src/backend/reader.js +++ b/plugins/dbgate-plugin-excel/src/backend/reader.js @@ -23,7 +23,7 @@ async function waitForDrain(stream) { }); } -async function reader({ fileName, sheetName, limitRows = undefined }) { +async function reader({ fileName, sheetName, skipHeaderRows, limitRows = undefined }) { const pass = new stream.PassThrough({ objectMode: true, highWaterMark: 100, @@ -32,10 +32,18 @@ async function reader({ fileName, sheetName, limitRows = undefined }) { const workbook = await loadWorkbook(fileName); const sheet = workbook.Sheets[sheetName]; + let range = undefined; + if (parseInt(skipHeaderRows) > 0) { + range = xlsx.utils.decode_range(sheet['!ref']); + range.s.r = parseInt(skipHeaderRows); + } + const rows = xlsx.utils.sheet_to_json(sheet, { header: 1, + range, blankrows: false, }); + const header = rows[0]; const structure = { __isStreamHeader: true, diff --git a/plugins/dbgate-plugin-excel/src/frontend/index.js b/plugins/dbgate-plugin-excel/src/frontend/index.js index 25ceab8b..8340d0e0 100644 --- a/plugins/dbgate-plugin-excel/src/frontend/index.js +++ b/plugins/dbgate-plugin-excel/src/frontend/index.js @@ -42,6 +42,14 @@ const fileFormat = { label: 'Create single file', direction: 'target', }, + { + type: 'number', + default: '0', + name: 'skipHeaderRows', + apiName: 'skipHeaderRows', + label: 'Skip header rows', + direction: 'source', + }, ], getDefaultOutputName: (sourceName, values) => {