88function main (
99 workbook : ExcelScript . Workbook ,
1010 tableName : string ,
11- columnsToFix : string [ ] ;
11+ columnsToFix : string [ ]
1212) {
1313 const table = workbook . getTable ( tableName ) ;
1414 if ( ! table ) {
@@ -17,22 +17,26 @@ function main(
1717
1818 // Process each column
1919 columnsToFix . forEach ( columnName => {
20- let column = table . getColumnByName ( columnName ) ;
20+ const column = table . getColumnByName ( columnName ) ;
21+ if ( ! column ) {
22+ throw new Error ( `Input key "${ columnName } " does not match any column in the table "${ tableName } ".` ) ;
23+ }
24+
2125 let values = column . getRange ( ) . getValues ( ) ;
2226
2327 // Loop through each row in the column
2428 for ( let i = 0 ; i < values . length ; i ++ ) {
25- let cellValue = values [ i ] [ 0 ] ;
29+ const cellValue = values [ i ] [ 0 ] ;
2630 if ( typeof cellValue !== "string" || cellValue . trim ( ) === "" ) {
2731 continue ;
2832 }
2933
3034 // Check if the value is all uppercase or all lowercase
3135 if ( cellValue === cellValue . toUpperCase ( ) || cellValue === cellValue . toLowerCase ( ) ) {
3236 // Convert to Proper Case while handling accents
33- let properCaseValue = cellValue . toLowerCase ( ) . replace (
37+ const properCaseValue = cellValue . toLowerCase ( ) . replace (
3438 / ( ^ | \\ s ) ( [ a - z á é í ó ú ü ñ â à ä ê ë î ï ô ö û ü ç ] ) / g,
35- ( _ , boundary , letter ) => boundary + letter . toUpperCase ( ) ;
39+ ( _ , boundary , letter ) => boundary + letter . toUpperCase ( )
3640 ) ;
3741
3842 // Update the value in the array
0 commit comments