fix(Google Sheets Node): Fix for auto-range detection

This commit is contained in:
Michael Kret 2023-01-06 00:25:28 +02:00 committed by GitHub
parent acfb3518ad
commit 77031a2950
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -582,6 +582,7 @@ export class GoogleSheet {
}
}
}
// Loop over all the lookup values and try to find a row to return
let rowIndex: number;
let returnColumnIndex: number;
@ -617,7 +618,13 @@ export class GoogleSheet {
}
}
return this.convertSheetDataArrayToObjectArray(removeEmptyColumns(returnData), 1, keys, true);
const dataWithoutEmptyColumns = removeEmptyColumns(returnData);
return this.convertSheetDataArrayToObjectArray(
dataWithoutEmptyColumns,
1,
dataWithoutEmptyColumns[0] as string[],
true,
);
}
private async convertObjectArrayToSheetDataArray(

View file

@ -134,6 +134,10 @@ export function removeEmptyColumns(data: SheetRangeData) {
const longestRow = data.reduce((a, b) => (a.length > b.length ? a : b), []).length;
for (let col = 0; col < longestRow; col++) {
const column = data.map((row) => row[col]);
if (column[0] !== '') {
returnData.push(column);
continue;
}
const hasData = column.slice(1).some((cell) => cell || typeof cell === 'number');
if (hasData) {
returnData.push(column);