Make it possible to define read-range on SpreadsheetFile-Node

This commit is contained in:
Jan Oberhauser 2020-10-12 11:41:34 +02:00
parent 7950c38f5a
commit e98fa3356d

View file

@ -12,6 +12,7 @@ import {
import {
read as xlsxRead,
Sheet2JSONOpts,
utils as xlsxUtils,
WorkBook,
write as xlsxWrite,
@ -233,6 +234,20 @@ export class SpreadsheetFile implements INodeType {
default: false,
description: 'In some cases and file formats, it is necessary to read<br />specifically as string else some special character get interpreted wrong.',
},
{
displayName: 'Range',
name: 'range',
type: 'string',
displayOptions: {
show: {
'/operation': [
'fromFile'
],
},
},
default: '',
description: 'The range to read from the table.<br />If set to a number it will be the starting row.<br />If set to string it will be used as A1-style bounded range.',
},
{
displayName: 'Sheet Name',
name: 'sheetName',
@ -317,7 +332,16 @@ export class SpreadsheetFile implements INodeType {
}
// Convert it to json
const sheetJson = xlsxUtils.sheet_to_json(workbook.Sheets[sheetName]);
const sheetToJsonOptions: Sheet2JSONOpts = {};
if (options.range) {
if (isNaN(options.range as number)) {
sheetToJsonOptions.range = options.range;
} else {
sheetToJsonOptions.range = parseInt(options.range as string, 10);
}
}
const sheetJson = xlsxUtils.sheet_to_json(workbook.Sheets[sheetName], sheetToJsonOptions);
// Check if data could be found in file
if (sheetJson.length === 0) {