Skip to content

Commit 7775ef5

Browse files
authored
adds incremental columns beyond 'Z' (ToolJet#2440)
1 parent dfd9e7a commit 7775ef5

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

plugins/packages/googlesheets/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export default class GooglesheetsQueryService implements QueryService {
132132
case "update":
133133
result = await batchUpdateToSheet(
134134
spreadsheetId,
135+
spreadsheetRange,
135136
queryOptions.sheet,
136137
queryOptions.body,
137138
queryOptionFilter,

plugins/packages/googlesheets/lib/operations.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@
166166
"className": "codehinter-plugins",
167167
"placeholder": "Enter spreadsheet_id"
168168
},
169+
"spreadsheet_range": {
170+
"label": "Range",
171+
"key": "spreadsheet_range",
172+
"type": "codehinter",
173+
"lineNumbers": false,
174+
"placeholder": "A1:Z500",
175+
"description": "Enter range",
176+
"width": "320px",
177+
"height": "36px",
178+
"className": "codehinter-plugins"
179+
},
169180
"sheet": {
170181
"label": "Sheet name",
171182
"key": "sheet",

plugins/packages/googlesheets/lib/operations.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ async function makeRequestToLookUpCellValues(spreadSheetId: string, range: strin
3535

3636
export async function batchUpdateToSheet(
3737
spreadSheetId: string,
38+
spreadsheetRange: string='A1:Z500',
3839
sheet: string='',
3940
requestBody: any,
4041
filterData: any,
@@ -45,7 +46,7 @@ export async function batchUpdateToSheet(
4546
return new Error('filterOperator is required');
4647
}
4748

48-
const lookUpData = await lookUpSheetData(spreadSheetId, sheet, authHeader);
49+
const lookUpData = await lookUpSheetData(spreadSheetId,spreadsheetRange, sheet, authHeader);
4950

5051
const updateBody = (requestBody, filterCondition, filterOperator, data) => {
5152
const rowsIndexes = getRowsIndex(filterCondition, filterOperator, data) as any[];
@@ -183,8 +184,8 @@ export async function deleteData(
183184
return await deleteDataFromSheet(spreadSheetId, sheet, rowIndex, authHeader);
184185
}
185186

186-
async function lookUpSheetData(spreadSheetId: string, sheet:string, authHeader: any) {
187-
const range = `${sheet}!A1:Z500`;
187+
async function lookUpSheetData(spreadSheetId: string, spreadsheetRange:string, sheet:string, authHeader: any) {
188+
const range = `${sheet}!${spreadsheetRange}`;
188189
const responseLookUpCellValues = await makeRequestToLookUpCellValues(spreadSheetId, range, authHeader);
189190
const data = await responseLookUpCellValues['values'];
190191

@@ -198,9 +199,14 @@ const getInputKeys = (inputBody, data) => {
198199
keys.map((key) =>
199200
data.filter((val, index) => {
200201
if (val[0] === key) {
201-
const kIndex = `${String.fromCharCode(65 + index)}`;
202-
arr.push({ col: val[0], colIndex: kIndex });
203-
}
202+
let keyIndex = '';
203+
if(index >= 26) {
204+
keyIndex = numberToLetters(index);
205+
} else {
206+
keyIndex = `${String.fromCharCode(65 + index)}`;
207+
}
208+
arr.push({ col: val[0], colIndex: keyIndex });
209+
}
204210
})
205211
);
206212
return arr;
@@ -236,3 +242,12 @@ const getRowsIndex = (inputFilter, filterOperator, response) => {
236242

237243
return rowIndex;
238244
};
245+
246+
function numberToLetters(num) {
247+
let letters = ''
248+
while (num >= 0) {
249+
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[num % 26] + letters
250+
num = Math.floor(num / 26) - 1
251+
}
252+
return letters
253+
}

0 commit comments

Comments
 (0)