mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
⚡ Make it possible to define read-range on SpreadsheetFile-Node
This commit is contained in:
parent
7950c38f5a
commit
e98fa3356d
|
@ -12,6 +12,7 @@ import {
|
||||||
|
|
||||||
import {
|
import {
|
||||||
read as xlsxRead,
|
read as xlsxRead,
|
||||||
|
Sheet2JSONOpts,
|
||||||
utils as xlsxUtils,
|
utils as xlsxUtils,
|
||||||
WorkBook,
|
WorkBook,
|
||||||
write as xlsxWrite,
|
write as xlsxWrite,
|
||||||
|
@ -233,6 +234,20 @@ export class SpreadsheetFile implements INodeType {
|
||||||
default: false,
|
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.',
|
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',
|
displayName: 'Sheet Name',
|
||||||
name: 'sheetName',
|
name: 'sheetName',
|
||||||
|
@ -317,7 +332,16 @@ export class SpreadsheetFile implements INodeType {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert it to json
|
// 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
|
// Check if data could be found in file
|
||||||
if (sheetJson.length === 0) {
|
if (sheetJson.length === 0) {
|
||||||
|
|
Loading…
Reference in a new issue