Skip to content

Commit

Permalink
fix(Google Sheets Node): Fix for auto-range detection
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency authored Jan 5, 2023
1 parent acfb351 commit 77031a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 77031a2

Please sign in to comment.