From dbfb8d56dc6290837701dea5957d4e73db418892 Mon Sep 17 00:00:00 2001 From: Nicholas Penree Date: Sun, 10 Jul 2022 02:54:52 -0400 Subject: [PATCH] feat(SpreadsheetFile Node): Allow skipping headers when writing spreadsheets (#3234) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ⚡ Allow skipping headers when writing spreadsheets * Fix type on sheet options --- .../nodes/SpreadsheetFile/SpreadsheetFile.node.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/nodes-base/nodes/SpreadsheetFile/SpreadsheetFile.node.ts b/packages/nodes-base/nodes/SpreadsheetFile/SpreadsheetFile.node.ts index c19bd922a9..04852eaa0e 100644 --- a/packages/nodes-base/nodes/SpreadsheetFile/SpreadsheetFile.node.ts +++ b/packages/nodes-base/nodes/SpreadsheetFile/SpreadsheetFile.node.ts @@ -9,6 +9,7 @@ import { } from 'n8n-workflow'; import { + JSON2SheetOpts, read as xlsxRead, Sheet2JSONOpts, utils as xlsxUtils, @@ -216,6 +217,7 @@ export class SpreadsheetFile implements INodeType { show: { '/operation': [ 'fromFile', + 'toFile', ], }, }, @@ -437,7 +439,10 @@ export class SpreadsheetFile implements INodeType { const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0) as string; const fileFormat = this.getNodeParameter('fileFormat', 0) as string; const options = this.getNodeParameter('options', 0, {}) as IDataObject; - + const sheetToJsonOptions: JSON2SheetOpts = {}; + if (options.headerRow === false) { + sheetToJsonOptions.skipHeader = true; + } // Get the json data of the items and flatten it let item: INodeExecutionData; const itemData: IDataObject[] = []; @@ -446,7 +451,7 @@ export class SpreadsheetFile implements INodeType { itemData.push(flattenObject(item.json)); } - const ws = xlsxUtils.json_to_sheet(itemData); + const ws = xlsxUtils.json_to_sheet(itemData, sheetToJsonOptions); const wopts: WritingOptions = { bookSST: false,