mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Make it possible to read RAW data from Spreadsheets
This commit is contained in:
parent
a75b844f0e
commit
a3ad579f89
|
@ -166,22 +166,36 @@ export class SpreadsheetFile implements INodeType {
|
||||||
name: 'options',
|
name: 'options',
|
||||||
type: 'collection',
|
type: 'collection',
|
||||||
placeholder: 'Add Option',
|
placeholder: 'Add Option',
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
operation: [
|
|
||||||
'toFile',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
default: {},
|
default: {},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
displayName: 'File Name',
|
displayName: 'File Name',
|
||||||
name: 'fileName',
|
name: 'fileName',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
'/operation': [
|
||||||
|
'toFile',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
default: '',
|
default: '',
|
||||||
description: 'File name to set in binary data. By default will "spreadsheet.<fileFormat>" be used.',
|
description: 'File name to set in binary data. By default will "spreadsheet.<fileFormat>" be used.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'RAW Data',
|
||||||
|
name: 'rawData',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
'/operation': [
|
||||||
|
'fromFile'
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
description: 'If the data should be returned RAW instead of parsed.',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -203,7 +217,8 @@ export class SpreadsheetFile implements INodeType {
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
item = items[i];
|
item = items[i];
|
||||||
|
|
||||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0) as string;
|
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i) as string;
|
||||||
|
const options = this.getNodeParameter('options', i, {}) as IDataObject;
|
||||||
|
|
||||||
if (item.binary === undefined || item.binary[binaryPropertyName] === undefined) {
|
if (item.binary === undefined || item.binary[binaryPropertyName] === undefined) {
|
||||||
// Property did not get found on item
|
// Property did not get found on item
|
||||||
|
@ -212,7 +227,7 @@ export class SpreadsheetFile implements INodeType {
|
||||||
|
|
||||||
// Read the binary spreadsheet data
|
// Read the binary spreadsheet data
|
||||||
const binaryData = Buffer.from(item.binary[binaryPropertyName].data, BINARY_ENCODING);
|
const binaryData = Buffer.from(item.binary[binaryPropertyName].data, BINARY_ENCODING);
|
||||||
const workbook = xlsxRead(binaryData);
|
const workbook = xlsxRead(binaryData, { raw: options.rawData as boolean });
|
||||||
|
|
||||||
if (workbook.SheetNames.length === 0) {
|
if (workbook.SheetNames.length === 0) {
|
||||||
throw new Error('File does not have any sheets!');
|
throw new Error('File does not have any sheets!');
|
||||||
|
@ -235,9 +250,9 @@ export class SpreadsheetFile implements INodeType {
|
||||||
return this.prepareOutputData(newItems);
|
return this.prepareOutputData(newItems);
|
||||||
} else if (operation === 'toFile') {
|
} else if (operation === 'toFile') {
|
||||||
// Write the workflow data to spreadsheet file
|
// Write the workflow data to spreadsheet file
|
||||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0) as string;
|
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i) as string;
|
||||||
const fileFormat = this.getNodeParameter('fileFormat', 0) as string;
|
const fileFormat = this.getNodeParameter('fileFormat', i) as string;
|
||||||
const options = this.getNodeParameter('options', 0, {}) as IDataObject;
|
const options = this.getNodeParameter('options', i, {}) as IDataObject;
|
||||||
|
|
||||||
// Get the json data of the items and flatten it
|
// Get the json data of the items and flatten it
|
||||||
let item: INodeExecutionData;
|
let item: INodeExecutionData;
|
||||||
|
|
Loading…
Reference in a new issue