mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
✨ Add support for files without headers to SpreadsheetFile node (#1738)
When false the first row of the spreadsheet file is considered a data row and each row is parsed as an array
This commit is contained in:
parent
ffc0c7b4d5
commit
43fae950e6
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"node": "n8n-nodes-base.spreadsheetFile",
|
"node": "n8n-nodes-base.spreadsheetFile",
|
||||||
"nodeVersion": "1.0",
|
"nodeVersion": "1.1",
|
||||||
"codexVersion": "1.0",
|
"codexVersion": "1.1",
|
||||||
"categories": [
|
"categories": [
|
||||||
"Data & Storage",
|
"Data & Storage",
|
||||||
"Core Nodes"
|
"Core Nodes"
|
||||||
|
|
|
@ -296,6 +296,20 @@ export class SpreadsheetFile implements INodeType {
|
||||||
default: 'Sheet',
|
default: 'Sheet',
|
||||||
description: 'Name of the sheet to create in the spreadsheet.',
|
description: 'Name of the sheet to create in the spreadsheet.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Header Row',
|
||||||
|
name: 'headerRow',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
'/operation': [
|
||||||
|
'fromFile',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: true,
|
||||||
|
description: 'Consider the first row as the header row or a data row.',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -359,6 +373,9 @@ export class SpreadsheetFile implements INodeType {
|
||||||
if (options.includeEmptyCells) {
|
if (options.includeEmptyCells) {
|
||||||
sheetToJsonOptions.defval = '';
|
sheetToJsonOptions.defval = '';
|
||||||
}
|
}
|
||||||
|
if (!options.headerRow) {
|
||||||
|
sheetToJsonOptions.header = 1; // Consider the first row as a data row
|
||||||
|
}
|
||||||
|
|
||||||
const sheetJson = xlsxUtils.sheet_to_json(workbook.Sheets[sheetName], sheetToJsonOptions);
|
const sheetJson = xlsxUtils.sheet_to_json(workbook.Sheets[sheetName], sheetToJsonOptions);
|
||||||
|
|
||||||
|
@ -368,9 +385,16 @@ export class SpreadsheetFile implements INodeType {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all the found data columns to the workflow data
|
// Add all the found data columns to the workflow data
|
||||||
|
if (options.headerRow) {
|
||||||
for (const rowData of sheetJson) {
|
for (const rowData of sheetJson) {
|
||||||
newItems.push({ json: rowData } as INodeExecutionData);
|
newItems.push({ json: rowData } as INodeExecutionData);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Data was returned as an array - https://github.com/SheetJS/sheetjs#json
|
||||||
|
for (const rowData of sheetJson) {
|
||||||
|
newItems.push({ json: { row: rowData } } as INodeExecutionData);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.prepareOutputData(newItems);
|
return this.prepareOutputData(newItems);
|
||||||
|
|
Loading…
Reference in a new issue