fix(Google Sheets Node): Tweaks (#7357)

Github issue / Community forum post (link here to close automatically):
This commit is contained in:
Michael Kret
2023-10-17 18:41:30 +03:00
committed by GitHub
parent a2d2e3dda7
commit d8531a53b9
10 changed files with 414 additions and 304 deletions

View File

@@ -5,9 +5,9 @@ import type {
IPollFunctions,
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { apiRequest } from '../transport';
import { utils as xlsxUtils } from 'xlsx';
import get from 'lodash/get';
import { apiRequest } from '../transport';
import type {
ILookupValues,
ISheetUpdateData,
@@ -553,6 +553,53 @@ export class GoogleSheet {
return { updateData, appendData };
}
/**
* Updates data in a sheet
*
* @param {IDataObject[]} inputData Data to update Sheet with
* @param {string} range The range to look for data
* @param {number} dataStartRowIndex Index of the first row which contains data
* @param {string[][]} columnNamesList The column names to use
* @returns {Promise<string[][]>}
* @memberof GoogleSheet
*/
prepareDataForUpdatingByRowNumber(
inputData: IDataObject[],
range: string,
columnNamesList: string[][],
) {
const decodedRange = this.getDecodedSheetRange(range);
const columnNames = columnNamesList[0];
const updateData: ISheetUpdateData[] = [];
for (const item of inputData) {
const updateRowIndex = item.row_number as number;
for (const name of columnNames) {
if (name === 'row_number') continue;
if (item[name] === undefined || item[name] === null) continue;
const columnToUpdate = this.getColumnWithOffset(
decodedRange.start?.column || 'A',
columnNames.indexOf(name),
);
let updateValue = item[name] as string;
if (typeof updateValue === 'object') {
try {
updateValue = JSON.stringify(updateValue);
} catch (error) {}
}
updateData.push({
range: `${decodedRange.name}!${columnToUpdate}${updateRowIndex}`,
values: [[updateValue]],
});
}
}
return { updateData };
}
/**
* Looks for a specific value in a column and if it gets found it returns the whole row
*