mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(Google Sheets Node): Tweaks (#7357)
Github issue / Community forum post (link here to close automatically):
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user