excel import - ability to skip header

This commit is contained in:
Jan Prochazka 2021-11-10 17:23:21 +01:00
parent aaf6ad8ab0
commit 6bcc83d920
3 changed files with 19 additions and 1 deletions

View File

@ -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'}

View File

@ -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,

View File

@ -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) => {