@@ -145,22 +145,24 @@ async function injectClientTemplateColumnsIntoSheet(workbook, sheetName, data) {
145145 // Headers
146146 countrySheet . getCell ( 'A1' ) . value = 'Country'
147147 countrySheet . getCell ( 'B1' ) . value = 'Currency'
148+ countrySheet . getCell ( 'C1' ) . value = 'Country Code'
148149 // find max nob length
149150 const maxNobs = Math . max ( ...data . map ( c => ( c . nob || [ ] ) . length ) )
150151 for ( let j = 0 ; j < maxNobs ; j ++ ) {
151- countrySheet . getCell ( 1 , 3 + j ) . value = `NOB${ j + 1 } `
152+ countrySheet . getCell ( 1 , 4 + j ) . value = `NOB${ j + 1 } `
152153 }
153154 // Fill rows
154155 data . forEach ( ( c , i ) => {
155156 const r = i + 2
156157 countrySheet . getCell ( r , 1 ) . value = c . country || ''
157158 countrySheet . getCell ( r , 2 ) . value = c . currency || ''
159+ countrySheet . getCell ( r , 3 ) . value = c . phonecode || ''
158160 ; ( c . nob || [ ] ) . forEach ( ( n , j ) => {
159- countrySheet . getCell ( r , 3 + j ) . value = n
161+ countrySheet . getCell ( r , 4 + j ) . value = n
160162 } )
161163 // Named range for each country NOBs
162- const fromCol = 3
163- const toCol = 2 + maxNobs
164+ const fromCol = 4
165+ const toCol = 3 + maxNobs
164166 const range = `${ countrySheet . name } !$${ String . fromCharCode ( 65 + fromCol - 1 ) } ${ r } :$${ String . fromCharCode ( 65 + toCol - 1 ) } ${ r } `
165167 // countrySheet.workbook.definedNames.addName(c.country.replace(/\s+/g, "_"), range)
166168 } )
@@ -181,6 +183,7 @@ async function injectClientTemplateColumnsIntoSheet(workbook, sheetName, data) {
181183 let colCountry = findHeaderCol ( [ 'Country*' , 'country' ] )
182184 let colNob = findHeaderCol ( [ 'Nature of Business*' , 'category' , 'NoB' ] )
183185 let colCurrency = findHeaderCol ( [ 'Currency*' , 'currency' ] )
186+ let colCountryCode = findHeaderCol ( [ 'Country Code' , 'country_code' ] )
184187 // Apply validations row-wise
185188 const maxRow = Math . max ( sheet . rowCount , 200 )
186189 for ( let row = 2 ; row <= maxRow ; row ++ ) {
@@ -193,7 +196,7 @@ async function injectClientTemplateColumnsIntoSheet(workbook, sheetName, data) {
193196 }
194197 // Nob dropdown (dependent on country)
195198 const nobCell = sheet . getRow ( row ) . getCell ( colNob )
196- const nobFormula = `=OFFSET(Countries!$C $2,MATCH(${ countryCell . address } ,Countries!$A$2:$A$${ lastRow } ,0)-1,0,1,COUNTA(OFFSET(Countries!$C $2,MATCH(${ countryCell . address } ,Countries!$A$2:$A$${ lastRow } ,0)-1,0,1,200)))`
199+ const nobFormula = `=OFFSET(Countries!$D $2,MATCH(${ countryCell . address } ,Countries!$A$2:$A$${ lastRow } ,0)-1,0,1,COUNTA(OFFSET(Countries!$D $2,MATCH(${ countryCell . address } ,Countries!$A$2:$A$${ lastRow } ,0)-1,0,1,200)))`
197200 nobCell . dataValidation = {
198201 type : 'list' ,
199202 allowBlank : true ,
@@ -204,6 +207,11 @@ async function injectClientTemplateColumnsIntoSheet(workbook, sheetName, data) {
204207 currencyCell . value = {
205208 formula : `=IF(${ countryCell . address } ="","",VLOOKUP(${ countryCell . address } ,Countries!$A$2:$B$${ lastRow } ,2,FALSE))`
206209 }
210+ //Country Code autofill
211+ const codeCell = sheet . getRow ( row ) . getCell ( colCountryCode )
212+ codeCell . value = {
213+ formula : `=IF(${ countryCell . address } ="","",VLOOKUP(${ countryCell . address } ,Countries!$A$2:$D$${ lastRow } ,3,FALSE))`
214+ }
207215 }
208216}
209217
0 commit comments