mirror of
https://github.com/dbgate/dbgate
synced 2024-11-22 16:27:18 +00:00
excel import - ability to skip header
This commit is contained in:
parent
aaf6ad8ab0
commit
6bcc83d920
@ -13,6 +13,8 @@
|
||||
|
||||
{#if arg.type == 'text'}
|
||||
<FormTextField label={arg.label} {name} defaultValue={arg.default} />
|
||||
{:else if arg.type == 'number'}
|
||||
<FormTextField label={arg.label} type="number" {name} defaultValue={arg.default} />
|
||||
{:else if arg.type == 'checkbox'}
|
||||
<FormCheckboxField label={arg.label} {name} defaultValue={arg.default} />
|
||||
{:else if arg.type == 'select'}
|
||||
|
@ -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,
|
||||
|
@ -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) => {
|
||||
|
Loading…
Reference in New Issue
Block a user