Skip to content

Commit f9b5f41

Browse files
committed
fix(scripts): correct syntax
1 parent abc0878 commit f9b5f41

4 files changed

Lines changed: 16 additions & 12 deletions

File tree

scripts/tables/convert-name-cases.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
function 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

scripts/tables/update-a-row.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ function main(
6464

6565
// Update each specified column
6666
let rowCell: ExcelScript.Range
67-
for (const [column, value] of Object.entries(updates)) {
68-
const colIndex = table.getColumnByName(column).getIndex();
67+
for (const [colName, value] of Object.entries(updates)) {
68+
const column = table.getColumnByName(colName);
6969

70-
if (colIndex === -1) {
70+
if (!column) {
7171
return {
7272
success: false,
7373
message: `Column "${keyColumnName}" not found`
7474
}
7575
}
7676

77-
rowCell = table.getColumnByName(column).getRangeBetweenHeaderAndTotal().getCell(targetRowIndex, 0);
77+
rowCell = column.getRangeBetweenHeaderAndTotal().getCell(targetRowIndex, 0);
7878
rowCell.setValue(value);
7979
}
8080

scripts/workbook-independant/get-differences-between-arrays.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
*/
1111
function main(
1212
workbook: ExcelScript.Workbook,
13-
initialArray: Array<object>,
14-
newArray: Array<object>,
13+
initialArray: Record<string, string>[],
14+
newArray: Record<string, string>[],
1515
idColName: string
1616
): {}[] {
1717
const output: { [key: string]: string }[] = [];

scripts/worksheets/replace-in-sheet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function main(
1515
matchCase: boolean = false,
1616
matchEntireCellContents: boolean = false
1717
) {
18-
const sheet: ExcelScript.Worksheet = workbook.getWorksheet(sheetName);
18+
const sheet = workbook.getWorksheet(sheetName);
1919
if (!sheet) {
2020
throw new Error(`Worksheet "${sheetName}" not found.`);
2121
}

0 commit comments

Comments
 (0)