@@ -35,6 +35,7 @@ async function makeRequestToLookUpCellValues(spreadSheetId: string, range: strin
35
35
36
36
export async function batchUpdateToSheet (
37
37
spreadSheetId : string ,
38
+ spreadsheetRange : string = 'A1:Z500' ,
38
39
sheet : string = '' ,
39
40
requestBody : any ,
40
41
filterData : any ,
@@ -45,7 +46,7 @@ export async function batchUpdateToSheet(
45
46
return new Error ( 'filterOperator is required' ) ;
46
47
}
47
48
48
- const lookUpData = await lookUpSheetData ( spreadSheetId , sheet , authHeader ) ;
49
+ const lookUpData = await lookUpSheetData ( spreadSheetId , spreadsheetRange , sheet , authHeader ) ;
49
50
50
51
const updateBody = ( requestBody , filterCondition , filterOperator , data ) => {
51
52
const rowsIndexes = getRowsIndex ( filterCondition , filterOperator , data ) as any [ ] ;
@@ -183,8 +184,8 @@ export async function deleteData(
183
184
return await deleteDataFromSheet ( spreadSheetId , sheet , rowIndex , authHeader ) ;
184
185
}
185
186
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 } ` ;
188
189
const responseLookUpCellValues = await makeRequestToLookUpCellValues ( spreadSheetId , range , authHeader ) ;
189
190
const data = await responseLookUpCellValues [ 'values' ] ;
190
191
@@ -198,9 +199,14 @@ const getInputKeys = (inputBody, data) => {
198
199
keys . map ( ( key ) =>
199
200
data . filter ( ( val , index ) => {
200
201
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
+ }
204
210
} )
205
211
) ;
206
212
return arr ;
@@ -236,3 +242,12 @@ const getRowsIndex = (inputFilter, filterOperator, response) => {
236
242
237
243
return rowIndex ;
238
244
} ;
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