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

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